const classafMorphia::Datastore
sys::Obj afMorphia::Datastore
(Service) - Wraps a MongoDB Collection, converting Fantom entities to / from Mongo documents.
- collection
const Collection collection
The underlying MongoDB collection this Datastore wraps.
- delete
Void delete(Obj entity, Bool checked := true)
Deletes the given entity from the MongoDB. Throws
ArgErr
ifchecked
and nothing was deleted.- deleteById
Void deleteById(Obj id, Bool checked := true)
Deletes entity with the given Id. Throws
ArgErr
ifchecked
and nothing was deleted.- drop
This drop(Bool checked := true)
Drops the underlying MongoDB collection.
- exists
Bool exists()
Returns
true
if the underlying MongoDB collection exists.- findAll
Obj[] findAll(Str:Obj? query := ([Str:Obj?])[:], Obj? sort := null, Int skip := 0, Int? limit := null)
Returns the result of the given
query
as a list of documents. Ifsort
is a Str it should the name of an index to use as a hint. Ifsort
is a[Str:Obj?]
map, it should be a sort document with field names as keys. Values may either be the standard Mongo1
and-1
for ascending / descending or the stringsASC
/DESC
.The
sort
map, should it contain more than 1 entry, must be ordered.- findCount
Returns the number of documents that would be returned by the given
query
.- findOne
Obj? findOne(Str:Obj? query, Bool checked := true)
Returns one document that matches the given
query
.Throws
MongoErr
if no documents are found andchecked
is true, returnsnull
otherwise. Always throwsMongoErr
if the query returns more than one document.- fromMongoDoc
Obj fromMongoDoc(Str:Obj? mongoDoc)
Converts the Mongo document to an entity instance.
- get
@
Operator
Obj? get(Obj id, Bool checked := true)Returns the document with the given Id. Convenience / shorthand notation for
findOne(["_id": id], checked)
- insert
Inserts the given entity. Returns the number of documents inserted.
- name
const Str name
The simple name of the MongoDB collection.
- qname
const Str qname
The qualified name of the MongoDB collection.
- size
Int size()
Returns the number of documents in the collection.
- toMongoDoc
Str:Obj? toMongoDoc(Obj entity)
Converts the entity instance to a Mongo document.
- type
const Type type
The Fantom entity type.
- update
Void update(Obj entity, Bool? upsert := (Bool?)false)
Updates the given entity.