const classafMongo::MongoColl

sys::Obj
  afMongo::MongoColl
aggregate

Source

MongoCur aggregate(Str:Obj?[] pipeline, |MongoCmd? optsFn := null)

connMgr

Source

const MongoConnMgr connMgr

The underlying connection manager.

count

Source

Int count([Str:Obj?]? filter := null)

Returns the number of documents that match the given filter. (Uses an aggregate cmd.)

create

Source

Void create(|MongoCmd? optsFn := null)

Creates a new collection explicitly.

There is usually no no need to call this unless you wish explicitly set collection options.

db.collection("name").create {
  it->capped = true
  it->size   = 64 * 1024  // no of bytes
  it->max    = 14         // no of docs
}

@see https://www.mongodb.com/docs/manual/reference/command/create/

db

Source

MongoDb db()

Creates an MongoDb instance of the associated DB.

dbName

Source

const Str dbName

The name of the database.

delete

Source

Int delete(Str:Obj? filter, |MongoCmd? optsFn := null)

Deletes all documents that match the given filter, and returns the number of documents deleted.

delete(["rick":"morty"]) {
  it->limit     = 1
  it->hint      = "_indexName_"
  it->collation = [...]
}

@see https://www.mongodb.com/docs/manual/reference/command/delete/

deleteAll

Source

Int deleteAll()

Deletes ALL documents in a Collection.

Note this is MUCH quicker than dropping the Collection.

drop

Source

Void drop(Bool force := false)

Drops this collection, but only if it exists.

Note that deleting all documents is MUCH quicker than dropping the Collection. See deleteAll for details.

If force is true then no checks are made. This will result in an error if the collection does not exist.

@see https://www.mongodb.com/docs/manual/reference/command/drop/

dropAllIndexes

Source

Void dropAllIndexes()

Drops ALL indexes on the collection. Be careful!

@see https://www.mongodb.com/docs/manual/reference/command/dropIndexes/

exists

Source

Bool exists()

Returns true if this collection exists.

find

Source

MongoCur find([Str:Obj?]? filter := null, |MongoCmd? optsFn := null)

Returns documents that match the given filter. Many options are possible.

find(["rick":"morty"]) {
  it->sort        = ["fieldName":1]
  it->hint        = "_indexName_"
  it->skip        = 50
  it->limit       = 100
  it->projection  = ["_id":1, "name":1]
  it->batchSize   = 101
  it->singleBatch = true
  it->collation   = [...]
}.toList
findAndDelete

Source

[Str:Obj?]? findAndDelete(Str:Obj? filter, |MongoCmd? optsFn := null)

Finds, deletes, and returns a single document. Returns null if no matching document was found.

@see https://www.mongodb.com/docs/manual/reference/command/findAndModify/

findAndUpdate

Source

[Str:Obj?]? findAndUpdate(Str:Obj? filter, Str:Obj? update, |MongoCmd? optsFn := null)

Finds, updates, and returns a single document. Returns null if no matching document was found.

@see https://www.mongodb.com/docs/manual/reference/command/findAndModify/

findOne

Source

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

Return one document that matches the given filter.

Throws an Err if no documents are found and checked is true.

Always throws Err if the filter returns more than one document.

@see https://www.mongodb.com/docs/manual/reference/command/find/

get

Source

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

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

index

Source

MongoIdx index(Str idxName)

Returns an MongoIdx of the given name.

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

insert

Source

Void insert(Str:Obj? document)

insertMany

Source

Void insertMany(Str:Obj?[] documents, |MongoCmd? optsFn := null)

Inserts many documents.

Default behaviour is to stop when inserting fails. See ordered option for details.

@see https://www.mongodb.com/docs/manual/reference/command/insert/

listIndexNames

Source

Str[] listIndexNames()

Returns all the index names in this collection.

listIndexes

Source

MongoCur listIndexes()

Returns all the indexes in this collection.

@see https://www.mongodb.com/docs/manual/reference/command/listIndexes/

make

Source

new make(MongoConnMgr connMgr, Str name, Str? dbName := 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.

name

Source

const Str name

The simple name of the collection.

qname

Source

Str qname()

Returns the qualified name of this collection. It takes the form of:

<database>.<collection>
replace

Source

Str:Obj? replace(Str:Obj? filter, Str:Obj? replacement, |MongoCmd? optsFn := null)

Finds a single document that matches the given filter, and replaces it. The _id field is NOT replaced.

replace(["rick":"morty"], ["rick":"sanchez"]) {
  it->upsert  = true
}

@see https://www.mongodb.com/docs/manual/reference/command/update/ @see https://www.mongodb.com/docs/manual/reference/operator/update/

size

Source

Int size()

Returns the number of documents in the collection.

The count is based on the collection's metadata, which provides a fast but sometimes inaccurate count for sharded clusters.

textSearch

Source

MongoCur textSearch(Str search, [Str:Obj?]? opts := null)

Performs a text search on the collection.

Text searching makes use of stemming and ignores language stop words. Quotes may be used to search for exact phrases and prefixing a word with a hyphen-minus (-) negates it.

Results are automatically ordered by search relevance.

To use text searching, make sure the Collection has a text Index else MongoDB will throw an Err.

col.textSearch("some text")

options may include the following:

Name

Type

Desc

$language

Bool

Determines the list of stop words for the search and the rules for the stemmer and tokenizer. See Supported Text Search Languages. Specify none for simple tokenization with no stop words and no stemming. Defaults to the language of the index.

$caseSensitive

Bool

Enable or disable case sensitive searching. Defaults to false.

$diacriticSensitive

Int

Enable or disable diacritic sensitive searching. Defaults to false.

Text searches may be mixed with regular filters. See MongoQ for details.

@see https://docs.mongodb.com/manual/reference/operator/query/text/.

update

Source

Str:Obj? update(Str:Obj? filter, Str:Obj? updates, |MongoCmd? optsFn := null)

Runs the given updateCmd against documents that match the given filter.

update(["rick":"morty"], ["\$set":["rick":"sanchez"]]) {
  it->upsert      = true
  it->multi       = false  // defaults to true
  it->hint        = "_indexName_"
  it->collation   = [...]
}

Inspect return value for upserted IDs.

(By default, this will update multiple documents.)

@see https://www.mongodb.com/docs/manual/reference/command/update/ @see https://www.mongodb.com/docs/manual/reference/operator/update/