const classafMongo::Collection
sys::Obj afMongo::Collection
Represents a MongoDB collection.
- aggregate
Str:Obj?[] aggregate(Str:Obj?[] pipeline, [Str:Obj?]? options := null)Performs an aggregation operation using a sequence of stage-based manipulations.
@see
- aggregateCursor
Obj? aggregateCursor(Str:Obj?[] pipeline, |Cursor->Obj? func)Same as
aggregate()but returns a cursor to iterate over the results.@see
- create
This create(Bool? autoIndexId := (Bool?)true, Bool? usePowerOf2Sizes := (Bool?)true)Creates a new collection explicitly.
@see http://docs.mongodb.org/manual/reference/command/create/
- createCapped
This createCapped(Int size, Int? maxNoOfDocs := null, Bool? autoIndexId := (Bool?)true, Bool? usePowerOf2Sizes := (Bool?)true)Creates a capped collection.
@see http://docs.mongodb.org/manual/reference/command/create/
- delete
Int delete(Str:Obj? query, Bool deleteAll := false, [Str:Obj?]? writeConcern := null)Deletes documents that match the given query. Returns the number of documents deleted.
If
deleteAllistruethen all documents matching the query will be deleted, otherwise only the first match will be deleted.@see http://docs.mongodb.org/manual/reference/command/delete/
- distinct
Obj[] distinct(Str field, [Str:Obj?]? query := null)Finds the distinct values for a specified field.
@see http://docs.mongodb.org/manual/reference/command/distinct/
- drop
This drop(Bool checked := true)Drops this collection.
- dropAllIndexes
This dropAllIndexes()Drops ALL indexes on the collection. Be careful!
@see http://docs.mongodb.org/manual/reference/command/dropIndexes/
- exists
Bool exists()Returns
trueif this collection exists.- find
Obj? find(Str:Obj? query, |Cursor->Obj? func)Creates a Cursor over the given
queryallowing you to iterate over results. Documents are downloaded from MongoDB in batches behind the scene as and when required. Usefind()to optomise iterating over a massive result set.Returns what is returned from the given cursor function.
second := collection.find([:]) |cursor->Obj?| { first := cursor.next second := cursor.next return second }@see Cursor
- findAll
Str:Obj?[] findAll(Str:Obj? query := ([Str:Obj?])[:], Obj? sort := null, Int skip := 0, Int? limit := null)Returns the result of the given
queryas a list of documents.If
sortis a Str it should the name of an index to use as a hint. Ifsortis a[Str:Obj?]map, it should be a sort document with field names as keys. Values may either be the standard Mongo1and-1for ascending / descending or the stringsASC/DESC.The
sortmap, should it contain more than 1 entry, must be ordered.@see Cursor.toList
- findAndDelete
Str:Obj? findAndDelete(Str:Obj? query, [Str:Obj?]? options := null)Updates and returns a single document.
Options Type ------- ---- sort Doc fields Doc
@see http://docs.mongodb.org/manual/reference/command/findAndModify/
- findAndUpdate
Str:Obj? findAndUpdate(Str:Obj? query, Str:Obj? updateCmd, Bool returnModified, [Str:Obj?]? options := null)Updates and returns a single document.
Options Type ------- ---- upsert Bool sort Doc fields Doc
@see http://docs.mongodb.org/manual/reference/command/findAndModify/
- findCount
Returns the number of documents that would be returned by the given
query.@see Cursor.count
- findOne
[Str:Obj?]? findOne(Str:Obj? query, Bool checked := true)An (optomised) method to return one document from the given
query.Throws
MongoErrif no documents are found andcheckedis true, returnsnullotherwise. Always throwsMongoErrif the query returns more than one document.- get
@Operator
[Str:Obj?]? get(Obj id, Bool checked := true)Convenience / shorthand notation for
findOne(["_id" : id], true)- group
Str:Obj?[] group(Obj key, Str:Obj? initial, Code reduceFunc, [Str:Obj?]? options := null)Groups documents by the specified key and performs simple aggregation functions.
keymust either be a list of field names (Str[]) or a function that creates a "key object" (Str).@see http://docs.mongodb.org/manual/reference/command/group/
- index
Index index(Str indexName)Returns an
Indexof the given name.Note this just instantiates the Fantom object, it does not create anything in the database.
- indexNames
Str[] indexNames()Returns all the index names of this collection.
- insert
Int insert(Str:Obj? document, [Str:Obj?]? writeConcern := null)Inserts the given document, Returns the number of documents inserted.
@see http://docs.mongodb.org/manual/reference/command/insert/
- makeFromDatabase
new makeFromDatabase(Database database, Str name, |This? f := null)Creates a
Collectionwith the given name under the database.Note this just instantiates the Fantom object, it does not create anything in the database.
- makeFromQname
new makeFromQname(ConnectionManager conMgr, Str qname, |This? f := null)Creates a
Collectionwith the given qualified (dot separated) name.Note this just instantiates the Fantom object, it does not create anything in the database.
- mapReduce
Str:Obj? mapReduce(Code mapFunc, Code reduceFunc, Obj out, [Str:Obj?]? options := null)Run a map-reduce aggregation operation over the collection.
If
outis a Str, it specifies the name of a collection to store the results. Ifoutis a Map, it specifies the action to take.@see http://docs.mongodb.org/manual/reference/command/mapReduce/
- name
Str name { private set }The simple name of the collection.
- qname
Str qname { private set }The qualified name of the collection. It takes the form of:
<database>.<collection>
- size
Int size()Returns the number of documents in the collection.
@see http://docs.mongodb.org/manual/reference/command/count/
- stats
Str:Obj? stats(Int scale := 1)Returns storage statistics for this collection.
@see http://docs.mongodb.org/manual/reference/command/collStats/
- update
Int update(Str:Obj? query, Str:Obj? updateCmd, Bool? multi := (Bool?)false, Bool? upsert := (Bool?)false, [Str:Obj?]? writeConcern := null)Runs the given
updateCmdagainst documents returned byquery. Returns the number of documents modified.@see http://docs.mongodb.org/manual/reference/command/update/
- writeConcern
const Str:Obj? writeConcern := MongoConstants.defaultWriteConcernThe write concern to use for collection writes.