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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| pipeline | org.bson.conversions.Bson[] | The aggregation pipeline. |
Return
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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| pipeline | java.util.List | The aggregation pipeline. |
Return
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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | The query filter. |
| options | com.mongodb.client.model.CountOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| keys | org.bson.conversions.Bson | An 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| options | com.mongodb.client.model.DeleteOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| options | com.mongodb.client.model.DeleteOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| options | com.mongodb.client.model.DropCollectionOptions | Various 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| options | com.mongodb.client.model.EstimatedDocumentCountOptions | The options describing the count. |
Return
( long )
The number of documents in the collection.
find
find() : MongoFindIterable
Description
Finds all documents in the collection.
Return
The find iterable interface.
find(filter: org.bson.conversions.Bson) : MongoFindIterable
Description
Finds all documents in the collection.
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | The query filter. |
Return
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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| options | com.mongodb.client.model.FindOneAndDeleteOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| data | Values | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| data | Values | The replacement document, which must not contain update operators. |
| options | com.mongodb.client.model.FindOneAndReplaceOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | java.util.List | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | java.util.List | A pipeline describing the update, which may not be null. |
| options | com.mongodb.client.model.FindOneAndUpdateOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | org.bson.conversions.Bson | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | org.bson.conversions.Bson | A document describing the update, which may not be null. The update to apply must include at least one update operator. |
| options | com.mongodb.client.model.FindOneAndUpdateOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| data | Values | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| data | Values | The data of the documents to insert. |
| options | com.mongodb.client.model.InsertManyOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| data | Values | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| data | Values | The data of the document to insert. |
| options | com.mongodb.client.model.InsertOneOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fullName | string | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| databaseName | string | The name of the database. |
| collectionName | string | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| data | Values | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| data | Values | The replacement document, which must not contain update operators. |
| options | com.mongodb.client.model.ReplaceOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | java.util.List | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | java.util.List | A pipeline describing the update, which may not be null. |
| options | com.mongodb.client.model.UpdateOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | org.bson.conversions.Bson | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | org.bson.conversions.Bson | A document describing the update, which may not be null. The update to apply must include at least one update operator. |
| options | com.mongodb.client.model.UpdateOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | java.util.List | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | java.util.List | A pipeline describing the update, which may not be null. |
| options | com.mongodb.client.model.UpdateOptions | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | org.bson.conversions.Bson | A 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | A document describing the query filter, which may not be null. |
| update | org.bson.conversions.Bson | A document describing the update, which may not be null. The update to apply must include at least one update operator. |
| options | com.mongodb.client.model.UpdateOptions | The options to apply to the update operation. |
Return
( long )
The result of the update one operation.