Collection Methods集合方法

mongo Shell Methods

The methods listed on this table of contents page refer to the mongo shell methods, and not to the MongoDB Node.js driver (or any other driver) methods. 此目录页上列出的方法指的是mongo shell方法,而不是MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档

Note

For details on specific methods, including syntax and examples, click on the specific method to go to its reference page.有关特定方法的详细信息,包括语法和示例,请单击特定方法以转到其参考页。

Name名称Description描述
db.collection.aggregate() Provides access to the aggregation pipeline.提供对聚合管道的访问。
db.collection.bulkWrite() Provides bulk write operation functionality.提供批量写入操作功能。
db.collection.copyTo() Deprecated. 不赞成。Copies data between collections when run against MongoDB 4.0 or earlier. 在MongoDB 4.0或更早版本上运行时,在集合之间复制数据。Unsupported when run against MongoDB 4.2 or later.在MongoDB 4.2或更高版本上运行时不受支持。
db.collection.count() Wraps count to return a count of the number of documents in a collection or a view.包装count以返回集合或视图中文档数的计数。
db.collection.countDocuments() Wraps the $group aggregation stage with a $sum expression to return a count of the number of documents in a collection or a view.包装使用$sum表达式的$group聚合阶段,以返回集合或视图中文档数的计数。
db.collection.estimatedDocumentCount() Wraps count to return an approximate count of the documents in a collection or a view.包装count以返回集合或视图中文档的大致计数。
db.collection.createIndex() Builds an index on a collection.在集合上建立索引。
db.collection.createIndexes() Builds one or more indexes on a collection.在集合上生成一个或多个索引。
db.collection.dataSize() Returns the size of the collection. 返回集合的大小。Wraps the size field in the output of the collStats.包装collStats输出中的size字段。
db.collection.deleteOne() Deletes a single document in a collection.删除集合中的单个文档。
db.collection.deleteMany() Deletes multiple documents in a collection.删除集合中的多个文档。
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.ensureIndex() Deprecated. 不赞成。Use db.collection.createIndex().请改用db.collection.createIndex()
db.collection.explain() Returns information on the query execution of various methods.返回有关各种方法的查询执行的信息。
db.collection.find() Performs a query on a collection or a view 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.findOneAndDelete() Finds a single document and deletes it.查找单个文档并将其删除。
db.collection.findOneAndReplace() Finds a single document and replaces it.查找单个文档并替换它。
db.collection.findOneAndUpdate() Finds a single document and updates it.查找单个文档并对其进行更新。
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.getShardDistribution()报告区块分布的数据。
db.collection.getShardVersion() Internal diagnostic method for sharded cluster.分片簇的内部诊断方法。
db.collection.hideIndex() Hides an index from the query planner.对查询计划器隐藏索引。
db.collection.insert() Creates a new document in a collection.在集合中创建新文档。
db.collection.insertOne() Inserts a new document in a collection.在集合中插入新文档。
db.collection.insertMany() Inserts several new document in a collection.在集合中插入多个新文档。
db.collection.isCapped() Reports if a collection is a capped collection.报告集合是否为上限集合
db.collection.latencyStats() Returns latency statistics for a collection.返回集合的延迟统计信息。
db.collection.mapReduce() Performs map-reduce style data aggregation.执行map reduce样式的数据聚合。
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.replaceOne() Replaces a single document in a collection.替换集合中的单个文档。
db.collection.save() Provides a wrapper around an insert() and update() to insert new documents.insert()update()周围提供包装器以插入新文档。
db.collection.stats() Reports on the state of a collection. 报告集合的状态。Provides a wrapper around the collStats.提供了一个关于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.collStats输出的storageSize字段周围提供包装器。
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.提供collStats输出的totalIndexSize字段的包装器。
db.collection.totalSize() Reports the total size of a collection, including the size of all documents and all indexes on a collection.报告集合的总大小,包括集合上所有文档和所有索引的大小。
db.collection.unhideIndex() Unhides an index from the query planner.从查询计划器中取消隐藏索引。
db.collection.update() Modifies a document in a collection.修改集合中的文档。
db.collection.updateOne() Modifies a single document in a collection.修改集合中的单个文档。
db.collection.updateMany() Modifies multiple documents in a collection.修改集合中的多个文档。
db.collection.watch() Establishes a Change Stream on a collection.在集合上建立更改流。
db.collection.validate() Performs diagnostic operations on a collection.对集合执行诊断操作。