mongodb的collection方法


 

 

 

方法名 描述
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.ensureIndex() 已過時,現使用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" : 。。。。。


 

 

 

 

 

 

 

 

 

 

 

 

#######################################################


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM