方法名 | 描述 |
db.collection.aggregate() | 聚合,主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果 |
db.collection.bulkWrite() | 批量写入 |
db.collection.createIndex() | 创建一个集合索引 |
db.collection.count() | 返回集合总数或匹配查询的结果集总数 |
db.collection.deleteOne() | 删除集合中的一个文档 |
db.collection.deleteMany() | 删除集合中的多个文档 |
db.collection.dataSize() | 返回集合的大小 |
db.collection.distinct() | 返回具有指定字段不同值的文档(去除指定字段的重复数据) |
db.collection.dropIndex() | 删除一个集合中的指定索引 |
db.collection.dropIndexes() | 删除一个集合中的所有索引 |
db.collection.drop() | 删除当前数据库中的collection集合 |
db.collection.explain() | 返回各种方法的查询执行信息 |
| 已过时,现使用db.collection.createIndex() |
db.collection.findOne() | 查询单条数据 |
db.collection.findOneAndReplace() | 查询单条数据并替换 |
db.collection.findOneAndDelete() | 查询单条数据并删除 |
db.collection.findOneAndUpdate() | 查询单条数据并更新 |
db.collection.find() | 查询集合,无参数则查询所有,并返回一个游标对象 |
db.collection.findAndModify() | 查询并修改 |
db.collection.getIndexes() | 返回当前集合的所有索引数组 |
db.collection.group() | 提供简单的数据聚合功能 |
db.collection.isCapped() | 判断集合是否为定容量 |
db.collection.insert() | 在当前集合插入一条或多条数据(或叫文档) |
db.collection.insertMany() | 在当前集合插入多条数据 |
db.collection.insertOne() | 在当前集合插入一条数据 |
db.collection.reIndex() | 重建当前集合的所有索引 |
db.collection.renameCollection() | 重命名集合名称 |
db.collection.replaceOne() | 替换集合中的一个文档(一条数据) |
db.collection.remove() | 从当前集合删除数据 |
db.collection.save() | 已插入数据更新 |
db.collection.stats() | 返回当前集合的状态 |
db.collection.storageSize() | 返回当前集合已使用的空间大小 |
db.collection.totalSize() | 返回当前集合的总占用空间,包括所有文件和所有索引 |
db.collection.totalIndexSize() | 返回当前集合所有的索引所占用的空间大小 |
db.collection.updateMany() | 修改集合中的多条数据 |
db.collection.update() | 修改集合中的数据 |
db.collection.updateOne() | 修改集合中的一条数据 |
db.collection.validate() | 执行对集合验证操作 |
##################################################################################################################################################################
获取集合详情:db.iphone.stats():
mongodb的每一个集合(table)对应着一个物理文件(dbpath/database_name/collection/xxx-yyy.wt),如何查看某个集合对应的物理文件名称呢?这个与mysql开启了innodb_file_per_table=1一致,均是一个表对应着一个物理文件,方便管理:
#############################################
#############################################
glc-test:PRIMARY> db.iphone.stats()
"ns" : "apple.iphone",
"uri" : "statistics:table:apple/collection/29-3120963922244296583",
##################################################################################
获取集合和索引详情:db.collection_name.stats({indexDetails:true})
获取集合中索引对应的物理文件(dbpath/database_name_index/xxx-yyy.wt):
"fetch_time_1_creation_time_1" : {
"metadata" : {
"formatVersion" : 8,
"infoObj" : "{ \"v\" : 2, \"key\" : { \"fetch_time\" : 1, \"creation_time\" : 1 }, \"name\" : \"fetch_time_1_creation_time_1\", \"ns\" : \"eagle.weibo\" }"
},
"type" : "file",
"uri" : "statistics:table:eagle/index/307-3120963922244296583",
"LSM" : 。。。。。
#######################################################