Collection Methods

Note

有关特定方法的详细信息,包括语法和示例,请单击特定方法以转到其参考页。

Name Description
db.collection.aggregate() 提供对aggregation pipeline的访问权限。
db.collection.bulkWrite() 提供批量写入操作功能。
db.collection.copyTo() 不推荐使用。包装eval以在单个 MongoDB 实例中的集合之间复制数据。
db.collection.count() 自动换行count返回集合或视图中文档数量的计数。
db.collection.createIndex() 在集合上构建索引。
db.collection.createIndexes() 在集合上构建一个或多个索引。
db.collection.dataSize() 返回集合的大小。在collStats的输出中包装size字段。
db.collection.deleteOne() 删除集合中的单个文档。
db.collection.deleteMany() 删除集合中的多个文档。
db.collection.distinct() 返回具有指定字段不同值的文档数组。
db.collection.drop() 从数据库中删除指定的集合。
db.collection.dropIndex() 删除集合上的指定索引。
db.collection.dropIndexes() 删除集合上的所有索引。
db.collection.ensureIndex() 不推荐使用。使用db.collection.createIndex()
db.collection.explain() 返回有关各种方法的查询执行的信息。
db.collection.find() 对集合或视图执行查询并返回游标对象。
db.collection.findAndModify() 以原子方式修改并返回单个文档。
db.collection.findOne() 执行查询并返回单个文档。
db.collection.findOneAndDelete() 查找单个文档并将其删除。
db.collection.findOneAndReplace() 查找单个文档并将其替换。
db.collection.findOneAndUpdate() 查找单个文档并进行更新。
db.collection.getIndexes() 返回描述集合中现有索引的文档数组。
db.collection.getShardDistribution() 对于分片群集中的集合,db.collection.getShardDistribution()报告chunk分布的数据。
db.collection.getShardVersion() 分片群集的内部诊断方法。
db.collection.group() 不推荐使用。提供简单的数据聚合功能。通过键将集合中的文档分组,然后处理结果。使用aggregate()进行更复杂的数据聚合。
db.collection.insert() 在集合中创建一个新文档。
db.collection.insertOne() 在集合中插入新文档。
db.collection.insertMany() 在集合中插入几个新文档。
db.collection.isCapped() 报告集合是否为capped collection
db.collection.latencyStats() 返回集合的延迟统计信息。
db.collection.mapReduce() 执行 map-reduce 样式数据聚合。
db.collection.reIndex() 重建集合上所有现有的索引。
db.collection.remove() 从集合中删除文档。
db.collection.renameCollection() 更改集合的名称。
db.collection.replaceOne() 替换集合中的单个文档。
db.collection.save() 提供围绕insert()update()的包装器以插入新文档。
db.collection.stats() 报告收集状态。提供围绕collStats的包装。
db.collection.storageSize() 报告集合使用的总大小(以字节为单位)。在collStats输出的storageSize字段周围提供包装。
db.collection.totalIndexSize() 报告集合中索引使用的总大小。在collStats输出的totalIndexSize字段周围提供包装。
db.collection.totalSize() 报告集合的总大小,包括集合中所有文档和所有索引的大小。
db.collection.update() 修改集合中的文档。
db.collection.updateOne() 修改集合中的单个文档。
db.collection.updateMany() 修改集合中的多个文档。
db.collection.watch() 在集合上构建变更流。
db.collection.validate() 对集合执行诊断操作。
首页