Skip to main content

MongoCollection

Allows you to interact with MongoDB collections.


aggregate


aggregate(pipeline: org.bson.conversions.Bson[]) : MongoAggregateIterable

Description

Aggregates documents according to the specified aggregation pipeline.

How To Use
const docs = collection.aggregate(
_mongo.aggregates().match(
_mongo.filters().eq('status', 'Active')
),
_mongo.aggregates().group(
'$customerId',
_mongo.accumulators().sum('total', '$price')
),
_mongo.aggregates().project(
_mongo.projections().fields(
_mongo.projections().include('total'),
_mongo.projections().excludeId()
)
)
).all();

Attributes
NAMETYPEDESCRIPTION
pipelineorg.bson.conversions.Bson[]The aggregation pipeline.
Return

( MongoAggregateIterable )

An iterable containing the result of the aggregation operation.


aggregate(pipeline: java.util.List<?>) : MongoAggregateIterable

Description

Aggregates documents according to the specified aggregation pipeline.

Attributes
NAMETYPEDESCRIPTION
pipelinejava.util.ListThe aggregation pipeline.
Return

( MongoAggregateIterable )

An iterable containing the result of the aggregation operation.


countDocuments


countDocuments() : long

Description

Counts the number of documents in the collection.

How To Use
collection.countDocuments();
Return

( long )

The number of documents in the collection.


countDocuments(filter: org.bson.conversions.Bson) : long

Description

Counts the number of documents in the collection.

How To Use
collection.countDocuments(_mongo.filters().eq('category', 'main'));
Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonThe query filter.
Return

( long )

The number of documents in the collection.


countDocuments(filter: org.bson.conversions.Bson, options: com.mongodb.client.model.CountOptions) : long

Description

Counts the number of documents in the collection.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonThe query filter.
optionscom.mongodb.client.model.CountOptionsThe options describing the count.
Return

( long )

The number of documents in the collection.


createIndex


createIndex(keys: org.bson.conversions.Bson) : string

Description

Create an index with the given keys.

How To Use
collection.createIndex(_mongo.indexes().ascending('quantity', 'price'));
Attributes
NAMETYPEDESCRIPTION
keysorg.bson.conversions.BsonAn object describing the index key(s), which may not be null.
Return

( string )

The index name.


deleteMany


deleteMany(filter: org.bson.conversions.Bson) : void

Description

Deletes multiple documents from the collection.

How To Use
collection.deleteMany(_mongo.filters().eq('status', 'Inactive'));
Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
Return

( void )


deleteMany(filter: org.bson.conversions.Bson, options: com.mongodb.client.model.DeleteOptions) : void

Description

Deletes multiple documents from the collection with the specified options.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
optionscom.mongodb.client.model.DeleteOptionsThe options to apply to the delete operation.
Return

( void )


deleteOne


deleteOne(filter: org.bson.conversions.Bson) : void

Description

Deletes a single document from the collection.

How To Use
collection.deleteOne(_mongo.filters().eq('name', 'Product'));
Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
Return

( void )


deleteOne(filter: org.bson.conversions.Bson, options: com.mongodb.client.model.DeleteOptions) : void

Description

Deletes a single document from the collection with the specified options.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
optionscom.mongodb.client.model.DeleteOptionsThe options to apply to the delete operation.
Return

( void )


drop


drop() : void

Description

Drops this collection from the Database.

Return

( void )


drop(options: com.mongodb.client.model.DropCollectionOptions) : void

Description

Drops this collection from the Database.

Attributes
NAMETYPEDESCRIPTION
optionscom.mongodb.client.model.DropCollectionOptionsVarious options for dropping the collection.
Return

( void )


estimatedDocumentCount


estimatedDocumentCount() : long

Description

Gets an estimate of the count of documents in a collection using collection metadata.

How To Use
collection.();
Return

( long )

The number of documents in the collection.


estimatedDocumentCount(options: com.mongodb.client.model.EstimatedDocumentCountOptions) : long

Description

Gets an estimate of the count of documents in a collection using collection metadata.

Attributes
NAMETYPEDESCRIPTION
optionscom.mongodb.client.model.EstimatedDocumentCountOptionsThe options describing the count.
Return

( long )

The number of documents in the collection.


find


find() : MongoFindIterable

Description

Finds all documents in the collection.

Return

( MongoFindIterable )

The find iterable interface.


find(filter: org.bson.conversions.Bson) : MongoFindIterable

Description

Finds all documents in the collection.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonThe query filter.
Return

( MongoFindIterable )

The find iterable interface.


findOneAndDelete


findOneAndDelete(filter: org.bson.conversions.Bson) : Values

Description

Atomically find a document and delete it.

How To Use
const old = collection.findOneAndDelete(_mongo.filters().eq('name', 'Product'));
Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
Return

( Values )

The found document, or null if no document matched.


findOneAndDelete(filter: org.bson.conversions.Bson, options: com.mongodb.client.model.FindOneAndDeleteOptions) : Values

Description

Atomically find a document and delete it.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
optionscom.mongodb.client.model.FindOneAndDeleteOptionsThe options to apply to the delete operation.
Return

( Values )

The found document, or null if no document matched.


findOneAndReplace


findOneAndReplace(filter: org.bson.conversions.Bson, data: Values) : Values

Description

Atomically find a document and replace it.

How To Use
const old = collection.findOneAndReplace(
_mongo.filters().eq('name', 'Product'),
_val.map()
.set('quantity', 200)
.set('price', 12.99)
.set('category', 'food')
);

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
dataValuesThe replacement document, which must not contain update operators.
Return

( Values )

The found document, or null if no document matched.


findOneAndReplace(filter: org.bson.conversions.Bson, data: Values, options: com.mongodb.client.model.FindOneAndReplaceOptions) : Values

Description

Atomically find a document and replace it.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
dataValuesThe replacement document, which must not contain update operators.
optionscom.mongodb.client.model.FindOneAndReplaceOptionsThe options to apply to the replace operation.
Return

( Values )

The found document, or null if no document matched.


findOneAndUpdate


findOneAndUpdate(filter: org.bson.conversions.Bson, update: java.util.List<?>) : Values

Description

Atomically find a document and update it.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updatejava.util.ListA pipeline describing the update, which may not be null.
Return

( Values )

The document that was updated before the update was applied. If no documents matched the query filter, then null will be returned.


findOneAndUpdate(filter: org.bson.conversions.Bson, update: java.util.List<?>, options: com.mongodb.client.model.FindOneAndUpdateOptions) : Values

Description

Atomically find a document and update it.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updatejava.util.ListA pipeline describing the update, which may not be null.
optionscom.mongodb.client.model.FindOneAndUpdateOptionsThe options to apply to the update operation.
Return

( Values )

The found document, or null if no document matched.


findOneAndUpdate(filter: org.bson.conversions.Bson, update: org.bson.conversions.Bson) : Values

Description

Atomically find a document and update it.

How To Use
const setUpdate = _mongo.updates().set('quantity', 42);
const renameUpdate = _mongo.updates().rename('other', 'more');

const combinedUpdates = _mongo.updates().combine(setUpdate, renameUpdate);

collection.findOneAndUpdate(
_mongo.filters().eq('name', 'Abc'),
combinedUpdates
);

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updateorg.bson.conversions.BsonA document describing the update, which may not be null. The update to apply must include at least one update operator.
Return

( Values )

The found document, or null if no document matched.


findOneAndUpdate(filter: org.bson.conversions.Bson, update: org.bson.conversions.Bson, options: com.mongodb.client.model.FindOneAndUpdateOptions) : Values

Description

Atomically find a document and update it.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updateorg.bson.conversions.BsonA document describing the update, which may not be null. The update to apply must include at least one update operator.
optionscom.mongodb.client.model.FindOneAndUpdateOptionsThe options to apply to the update operation.
Return

( Values )

The found document, or null if no document matched.


insertMany


insertMany(data: Values) : java.util.List<string>

Description

Inserts multiple documents into the collection.

Attributes
NAMETYPEDESCRIPTION
dataValuesThe data of the documents to insert.
Return

( java.util.List )

The list of IDs of the inserted documents.


insertMany(data: Values, options: com.mongodb.client.model.InsertManyOptions) : java.util.List<string>

Description

Inserts multiple documents into the collection with the specified options.

Attributes
NAMETYPEDESCRIPTION
dataValuesThe data of the documents to insert.
optionscom.mongodb.client.model.InsertManyOptionsThe options to apply to the insert operation.
Return

( java.util.List )

The list of IDs of the inserted documents.


insertOne


insertOne(data: Values) : string

Description

Inserts a single document into the collection.

How To Use
const id = collection.insertOne(
_val.map()
.set('name', 'Abc')
.set('quantity', 100)
.set('price', 9.99)
.set('category', 'main')
);

Attributes
NAMETYPEDESCRIPTION
dataValuesThe data of the document to insert.
Return

( string )

The ID of the inserted document.


insertOne(data: Values, options: com.mongodb.client.model.InsertOneOptions) : string

Description

Inserts a single document into the collection with the specified options.

Attributes
NAMETYPEDESCRIPTION
dataValuesThe data of the document to insert.
optionscom.mongodb.client.model.InsertOneOptionsThe options to apply to the insert operation.
Return

( string )

The ID of the inserted document.


renameCollection


renameCollection(fullName: string) : void

Description

Renames the collection to the provided full name.

How To Use
collection.renameCollection('database.newCollection');
Attributes
NAMETYPEDESCRIPTION
fullNamestringThe full name of the new collection in the format 'database.collection'.
Return

( void )


renameCollection(databaseName: string, collectionName: string) : void

Description

Renames the collection to the provided database name and collection name.

How To Use
collection.renameCollection('database', 'newCollection');
Attributes
NAMETYPEDESCRIPTION
databaseNamestringThe name of the database.
collectionNamestringThe new name of the collection.
Return

( void )


replaceOne


replaceOne(filter: org.bson.conversions.Bson, data: Values) : long

Description

Replace a single document in the collection according to the specified filter.

How To Use
collection.replaceOne(
_mongo.filters().eq('name', 'Product'),
_val.map()
.set('quantity', 200)
.set('price', 12.99)
.set('category', 'food')
);

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
dataValuesThe replacement document, which must not contain update operators.
Return

( long )

The number of modified documents.


replaceOne(filter: org.bson.conversions.Bson, data: Values, options: com.mongodb.client.model.ReplaceOptions) : long

Description

Replace a single document in the collection according to the specified filter.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
dataValuesThe replacement document, which must not contain update operators.
optionscom.mongodb.client.model.ReplaceOptionsThe options to apply to the replace operation.
Return

( long )

The number of modified documents.


updateMany


updateMany(filter: org.bson.conversions.Bson, update: java.util.List<?>) : long

Description

Update multiple documents in the collection according to the specified arguments.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updatejava.util.ListA pipeline describing the update, which may not be null.
Return

( long )

The number of modified documents.


updateMany(filter: org.bson.conversions.Bson, update: java.util.List<?>, options: com.mongodb.client.model.UpdateOptions) : long

Description

Update multiple documents in the collection according to the specified arguments.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updatejava.util.ListA pipeline describing the update, which may not be null.
optionscom.mongodb.client.model.UpdateOptionsThe options to apply to the update operation.
Return

( long )

The number of modified documents.


updateMany(filter: org.bson.conversions.Bson, update: org.bson.conversions.Bson) : long

Description

Update multiple documents in the collection according to the specified arguments.

How To Use
collection.updateMany(
_mongo.filters().eq('status', 'Active'),
_mongo.updates().set('status', 'Inactive')
);

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updateorg.bson.conversions.BsonA document describing the update, which may not be null. The update to apply must include at least one update operator.
Return

( long )

The number of modified documents.


updateMany(filter: org.bson.conversions.Bson, update: org.bson.conversions.Bson, options: com.mongodb.client.model.UpdateOptions) : long

Description

Update multiple documents in the collection according to the specified arguments.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updateorg.bson.conversions.BsonA document describing the update, which may not be null. The update to apply must include at least one update operator.
optionscom.mongodb.client.model.UpdateOptionsThe options to apply to the update operation.
Return

( long )

The number of modified documents.


updateOne


updateOne(filter: org.bson.conversions.Bson, update: java.util.List<?>) : long

Description

Update a single document in the collection according to the specified arguments.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updatejava.util.ListA pipeline describing the update, which may not be null.
Return

( long )

The result of the update one operation.


updateOne(filter: org.bson.conversions.Bson, update: java.util.List<?>, options: com.mongodb.client.model.UpdateOptions) : long

Description

Update a single document in the collection according to the specified arguments.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updatejava.util.ListA pipeline describing the update, which may not be null.
optionscom.mongodb.client.model.UpdateOptionsThe options to apply to the update operation.
Return

( long )

The result of the update one operation.


updateOne(filter: org.bson.conversions.Bson, update: org.bson.conversions.Bson) : long

Description

Update a single document in the collection according to the specified arguments.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updateorg.bson.conversions.BsonA document describing the update, which may not be null. The update to apply must include at least one update operator.
Return

( long )

The result of the update one operation.


updateOne(filter: org.bson.conversions.Bson, update: org.bson.conversions.Bson, options: com.mongodb.client.model.UpdateOptions) : long

Description

Update a single document in the collection according to the specified arguments.

Attributes
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonA document describing the query filter, which may not be null.
updateorg.bson.conversions.BsonA document describing the update, which may not be null. The update to apply must include at least one update operator.
optionscom.mongodb.client.model.UpdateOptionsThe options to apply to the update operation.
Return

( long )

The result of the update one operation.