const classafMongo::Collection

sys::Obj
  afMongo::Collection

Represents a MongoDB collection.

aggregate

Source

Str:Obj?[] aggregate(Str:Obj?[] pipeline, [Str:Obj?]? options := null)

Performs an aggregation operation using a sequence of stage-based manipulations.

@see

aggregateCursor

Source

Obj? aggregateCursor(Str:Obj?[] pipeline, |Cursor->Obj? func)

create

Source

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

Source

This createCapped(Int size, Int? maxNoOfDocs := null, Bool? autoIndexId := (Bool?)true, Bool? usePowerOf2Sizes := (Bool?)true)

delete

Source

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 deleteAll is true then 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

Source

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

Source

This drop(Bool checked := true)

dropAllIndexes

Source

This dropAllIndexes()

Drops ALL indexes on the collection. Be careful!

@see http://docs.mongodb.org/manual/reference/command/dropIndexes/

exists

Source

Bool exists()

Returns true if this collection exists.

find

Source

Obj? find(Str:Obj? query, |Cursor->Obj? func)

Creates a Cursor over the given query allowing you to iterate over results. Documents are downloaded from MongoDB in batches behind the scene as and when required. Use find() 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

Source

Str: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 Cursor.toList

findAndDelete

Source

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

Source

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

Source

Int findCount(Str:Obj? query)

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

@see Cursor.count

findOne

Source

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

An (optomised) method to return one document from 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.

get

Source

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

Convenience / shorthand notation for findOne(["_id" : id], true)

group

Source

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.

key must 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

Source

Index index(Str indexName)

Returns an Index of the given name.

Note this just instantiates the Fantom object, it does not create anything in the database.

indexNames

Source

Str[] indexNames()

Returns all the index names of this collection.

insert

Source

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

Source

new makeFromDatabase(Database database, Str name, |This? f := null)

Creates a Collection with the given name under the database.

Note this just instantiates the Fantom object, it does not create anything in the database.

makeFromQname

Source

new makeFromQname(ConnectionManager conMgr, Str qname, |This? f := null)

Creates a Collection with the given qualified (dot separated) name.

Note this just instantiates the Fantom object, it does not create anything in the database.

mapReduce

Source

Str:Obj? mapReduce(Code mapFunc, Code reduceFunc, Obj out, [Str:Obj?]? options := null)

Run a map-reduce aggregation operation over the collection.

If out is a Str, it specifies the name of a collection to store the results. If out is a Map, it specifies the action to take.

@see http://docs.mongodb.org/manual/reference/command/mapReduce/

name

Source

Str name { private set }

The simple name of the collection.

qname

Source

Str qname { private set }

The qualified name of the collection. It takes the form of:

<database>.<collection>
size

Source

Int size()

Returns the number of documents in the collection.

@see http://docs.mongodb.org/manual/reference/command/count/

stats

Source

Str:Obj? stats(Int scale := 1)

Returns storage statistics for this collection.

@see http://docs.mongodb.org/manual/reference/command/collStats/

update

Source

Int update(Str:Obj? query, Str:Obj? updateCmd, Bool? multi := (Bool?)false, Bool? upsert := (Bool?)false, [Str:Obj?]? writeConcern := null)

Runs the given updateCmd against documents returned by query. Returns the number of documents modified.

@see http://docs.mongodb.org/manual/reference/command/update/

writeConcern

Source

const Str:Obj? writeConcern := MongoConstants.defaultWriteConcern

The write concern to use for collection writes.