w3resource

Mongodb Shell methods

Collection

Methods are below in the table

Name Description
db.collection.aggregate() Provides access to the aggregation pipeline.
db.collection.count() Wraps count to return a count of the number of documents in a collection or matching a query.
db.collection.createIndex() Builds an index on a collection.
db.collection.dataSize() Returns the size of the collection. Wraps the size field in the output of the collStats.
db.collection.distinct() Returns an array of documents that have distinct values for the specified field.
db.collection.drop() Removes the specified collection from the database.
db.collection.dropIndex() Removes a specified index on a collection.
db.collection.dropIndexes() Removes all indexes on a collection
db.collection.explain() Returns information on the query execution of various methods.
db.collection.find() Performs a query on a collection and returns a cursor object.
db.collection.findAndModify() Atomically modifies and returns a single document.
db.collection.findOne() Performs a query and returns a single document.
db.collection.getIndexes() Returns an array of documents that describe the existing indexes on a collection.
db.collection.getShardDistribution() For collections in sharded clusters, db.collection.getShardDistribution() reports data of chunk distribution.
db.collection.getShardVersion() Internal diagnostic method for shard cluster.
db.collection.group() Provides simple data aggregation function. Groups documents in a collection by a key, and processes the results. Use aggregate() for more complex data aggregation.
db.collection.insert() Creates a new document in a collection.
db.collection.isCapped() Reports if a collection is a capped collection.
db.collection.mapReduce() Performs map-reduce style data aggregation.
db.collection.reIndex() Rebuilds all existing indexes on a collection.
db.collection.remove() Deletes documents from a collection.
db.collection.renameCollection() Changes the name of a collection.
db.collection.save() Provides a wrapper around an insert() and update() to insert new documents.
db.collection.stats() Reports on the state of a collection. Provides a wrapper around the collStats.
db.collection.storageSize() Reports the total size used by the collection in bytes. Provides a wrapper around the storageSize field of the collStats output.
db.collection.totalSize() Reports the total size of a collection, including the size of all documents and all indexes on a collection.
db.collection.totalIndexSize() Reports the total size used by the indexes on a collection. Provides a wrapper around the totalIndexSize field of the collStats output.
db.collection.update() Modifies a document in a collection.
db.collection.validate() Performs diagnostic operations on a collection.

User Management

Name Description
db.auth() Authenticates a user to a database.
db.createUser() Creates a new user.
db.updateUser() Updates user data.
db.changeUserPassword() Changes an existing user’s password.
db.dropAllUsers() Deletes all users associated with a database.
db.dropUser() Removes a single user.
db.grantRolesToUser() Grants a role and its privileges to a user.
db.revokeRolesFromUser() Removes a role from a user.
db.getUser() Returns information about the specified user.
db.getUsers() Returns information about all users associated with a database.

Previous: MongoDB Single Field Index
Next: db.collection.aggregate() method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/mongodb/shell-methods/index.php