Constructor
new MongoCollection()
Methods
aggregate(pipeline)
Create a cursor to execute and return results form an aggregation pipeline.
Parameters:
Name | Type | Description |
---|---|---|
pipeline |
Array.<Object> |
Returns:
MongoCursor with results
(async) countDocuments(query)
Count how many documents match query without returning them
Parameters:
Name | Type | Description |
---|---|---|
query |
Object |
Returns:
number of matching documents
(async) createIndex(name, definition)
Define a MongoDB Database BTree index.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | |
definition |
Object |
Returns:
Object showing success or failure
(async) createSearchIndex(name, definition)
Define an Atlas Search index.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | |
definition |
Object |
Returns:
Object showing success or failure
(async) deleteMany(query)
Delete all documents matching query.
Parameters:
Name | Type | Description |
---|---|---|
query |
Object |
Returns:
ject showing how many were found and deleted
(async) deleteOne(query)
Delete first document matching query found.
Parameters:
Name | Type | Description |
---|---|---|
query |
Object |
Returns:
Object showing how many were found and deleted
(async) drop()
Drop this colleciton and all non search indexes
Returns:
Object showing success or failure
(async) dropIndex(name)
Define a MongoDB Database BTree index.
Parameters:
Name | Type | Description |
---|---|---|
name |
String |
Returns:
Object showing success or failure
(async) dropSearchIndex(name)
Drop an Atlas Search index.
Parameters:
Name | Type | Description |
---|---|---|
name |
String |
Returns:
Object showing success or failure
find(query, projection)
Create a Cursor to define a search and set the filter and projection parameters
This does not execute the search until you start to itterate the cursor.
Parameters:
Name | Type | Description |
---|---|---|
query |
Object | |
projection |
Object |
Returns:
MongoCursor - used to access the results
(async) findOne(query, projection)
Immediately execute the query specified and return the first document found.
Parameters:
Name | Type | Description |
---|---|---|
query |
Object | |
projection |
Object |
Returns:
Document Object
(async) findOneAndUpdate(query, updates, {Object)
Update a single document identified by the query according to the supplied updates then
return either the document before(default) or after those changes. options is used to specify
whather before or after as well as projection and sort order to apply and whther to upsert.
Parameters:
Name | Type | Description |
---|---|---|
query |
Object | |
updates |
Object | |
{Object |
options |
Returns:
Document updated or null
(async) insertMany(document)
Add multiple Documents (Objects) to this collection.
Parameters:
Name | Type | Description |
---|---|---|
document |
Array.<Object> |
Returns:
Object showing sucess or failure and the primary keys (_id) of all the object added.
(async) insertOne(document)
Add a single Document (Object) to this collection.
Parameters:
Name | Type | Description |
---|---|---|
document |
Object |
Returns:
Object showing sucess or failure and the primary key (_id) of the object added.
(async) listIndexes()
List all Atlas Search indexes on this collection.
Returns:
Array of MongoDB Database BTree index definition Objects
(async) listSearchIndexes()
List all Atlas Search indexes on this collection.
Returns:
Array of Atlas Search index definition Objects
(async) updateMany(query, updates, options)
Apply the updates specified to all documents matching query.
Parameters:
Name | Type | Description |
---|---|---|
query |
Object | |
updates |
Object | |
options |
Object |
Returns:
Object showing how many were found and updated
(async) updateOne(query, updates, options)
Apply the updates specified to the first document matching query.
Parameters:
Name | Type | Description |
---|---|---|
query |
Object | |
updates |
Object | |
options |
Object |
Returns:
Object showing how many were found and updated