const classafMorphia::Datastore

sys::Obj
  afMorphia::Datastore

(Service) - Wraps a MongoDB Collection, converting Fantom entities to / from Mongo documents.

When injecting as a service, use the @DatastoreType facet to state which Entity type it is for:

@Inject @DatastoreType { type=MyEntity# }
private const Datastore myEntityDatastore
collection

Source

const Collection collection

The underlying MongoDB collection this Datastore wraps.

delete

Source

Void delete(Obj entity, Bool checked := true)

Deletes the given entity from the MongoDB. Throws ArgErr if checked and nothing was deleted.

@see afMongo::Collection.delete

deleteById

Source

Void deleteById(Obj id, Bool checked := true)

Deletes entity with the given Id. Throws ArgErr if checked and nothing was deleted.

@see afMongo::Collection.delete

drop

Source

This drop(Bool checked := true)

Drops the underlying MongoDB collection.

@see afMongo::Collection.drop

exists

Source

Bool exists()

Returns true if the underlying MongoDB collection exists.

@see afMongo::Collection.exists

findAll

Source

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. If sort is a Str it should the name of an index to use as a hint. If sort is a [Str:Obj?] map, it should be a sort document with field names as keys. Values may either be the standard Mongo 1 and -1 for ascending / descending or the strings ASC / DESC.

The sort map, should it contain more than 1 entry, must be ordered.

@see afMongo::Collection.findAll

findCount

Source

Int findCount(Str:Obj? query)

Returns the number of documents that would be returned by the given query.

@see afMongo::Collection.findCount

findOne

Source

Obj? findOne(Str:Obj? query, Bool checked := true)

Returns one document that matches the given query.

Throws MongoErr if no documents are found and checked is true, returns null otherwise. Always throws MongoErr if the query returns more than one document.

@see afMongo::Collection.findOne

fromMongoDoc

Source

Obj fromMongoDoc(Str:Obj? mongoDoc)

Converts the Mongo document to an entity instance.

get

Source

@Operator
Obj? get(Obj id, Bool checked := true)

Returns the document with the given Id. Convenience / shorthand notation for findOne(["_id": id], checked)

insert

Source

Void insert(Obj entity)

Inserts the given entity. Returns the number of documents inserted.

@see afMongo::Collection.insert

name

Source

const Str name

The simple name of the MongoDB collection.

qname

Source

const Str qname

The qualified name of the MongoDB collection.

size

Source

Int size()

Returns the number of documents in the collection.

@see afMongo::Collection.size

toMongoDoc

Source

Str:Obj? toMongoDoc(Obj entity)

Converts the entity instance to a Mongo document.

type

Source

const Type type

The Fantom entity type.

update

Source

Void update(Obj entity, Bool? upsert := (Bool?)false)

Updates the given entity.

@see afMongo::Collection.update