mongodb集合API

集合上的方法

db.test.addIdIfNeeded(              db.test.getSplitKeysForChunks(
db.test.aggregate(                  db.test.getWriteConcern(
db.test.bulkWrite(                  db.test.group(
db.test.constructor                 db.test.groupcmd(
db.test.convertToCapped(            db.test.hasOwnProperty
db.test.convertToSingleObject(      db.test.hashAllDocs(
db.test.copyTo(                     db.test.help(
db.test.count(                      db.test.initializeOrderedBulkOp(
db.test.countDocuments(             db.test.initializeUnorderedBulkOp(
db.test.createIndex(                db.test.insert(
db.test.createIndexes(              db.test.insertMany(
db.test.dataSize(                   db.test.insertOne(
db.test.deleteMany(                 db.test.isCapped(
db.test.deleteOne(                  db.test.latencyStats(
db.test.distinct(                   db.test.mapReduce(
db.test.drop(                       db.test.propertyIsEnumerable
db.test.dropIndex(                  db.test.prototype
db.test.dropIndexes(                db.test.reIndex(
db.test.ensureIndex(                db.test.remove(
db.test.estimatedDocumentCount(     db.test.renameCollection(
db.test.exists(                     db.test.replaceOne(
db.test.explain(                    db.test.runCommand(
db.test.find(                       db.test.runReadCommand(
db.test.findAndModify(              db.test.save(
db.test.findOne(                    db.test.setSlaveOk(
db.test.findOneAndDelete(           db.test.setWriteConcern(
db.test.findOneAndReplace(          db.test.shellPrint(
db.test.findOneAndUpdate(           db.test.stats(
db.test.getCollection(              db.test.storageSize(
db.test.getDB(                      db.test.toLocaleString
db.test.getFullName(                db.test.toString(
db.test.getIndexKeys(               db.test.tojson(
db.test.getIndexSpecs(              db.test.totalIndexSize(
db.test.getIndexes(                 db.test.totalSize(
db.test.getIndices(                 db.test.unsetWriteConcern(
db.test.getMongo(                   db.test.update(
db.test.getName(                    db.test.updateMany(
db.test.getPlanCache(               db.test.updateOne(
db.test.getQueryOptions(            db.test.validate(
db.test.getShardDistribution(       db.test.valueOf
db.test.getShardVersion(            db.test.verify(
db.test.getSlaveOk(

集合方法說明

    db.test.find().help() - show DBCursor help
    db.test.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
    db.test.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
    db.test.countDocuments( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
    db.test.estimatedDocumentCount( <optional params> ) - estimate the document count using collection metadata, optional parameters are: maxTimeMS
    db.test.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
    db.test.convertToCapped(maxBytes) - calls {convertToCapped:'test', size:maxBytes}} command
    db.test.createIndex(keypattern[,options])
    db.test.createIndexes([keypatterns], <options>)
    db.test.dataSize()
    db.test.deleteOne( filter, <optional params> ) - delete first matching document, optional parameters are: w, wtimeout, j
    db.test.deleteMany( filter, <optional params> ) - delete all matching documents, optional parameters are: w, wtimeout, j
    db.test.distinct( key, query, <optional params> ) - e.g. db.test.distinct( 'x' ), optional parameters are: maxTimeMS
    db.test.drop() drop the collection
    db.test.dropIndex(index) - e.g. db.test.dropIndex( "indexName" ) or db.test.dropIndex( { "indexKey" : 1 } )
    db.test.dropIndexes()
    db.test.ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead
    db.test.explain().help() - show explain help
    db.test.reIndex()
    db.test.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
                                                  e.g. db.test.find( {x:77} , {name:1, x:1} )
    db.test.find(...).count()
    db.test.find(...).limit(n)
    db.test.find(...).skip(n)
    db.test.find(...).sort(...)
    db.test.findOne([query], [fields], [options], [readConcern])
    db.test.findOneAndDelete( filter, <optional params> ) - delete first matching document, optional parameters are: projection, sort, maxTimeMS
    db.test.findOneAndReplace( filter, replacement, <optional params> ) - replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
    db.test.findOneAndUpdate( filter, update, <optional params> ) - update first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
    db.test.getDB() get DB object associated with collection
    db.test.getPlanCache() get query plan cache associated with collection
    db.test.getIndexes()
    db.test.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
    db.test.insert(obj)
    db.test.insertOne( obj, <optional params> ) - insert a document, optional parameters are: w, wtimeout, j
    db.test.insertMany( [objects], <optional params> ) - insert multiple documents, optional parameters are: w, wtimeout, j
    db.test.mapReduce( mapFunction , reduceFunction , <optional params> )
    db.test.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
    db.test.remove(query)
    db.test.replaceOne( filter, replacement, <optional params> ) - replace the first matching document, optional parameters are: upsert, w, wtimeout, j
    db.test.renameCollection( newName , <dropTarget> ) renames the collection.
    db.test.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
    db.test.save(obj)
    db.test.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>})
    db.test.storageSize() - includes free space allocated to this collection
    db.test.totalIndexSize() - size in bytes of all the indexes
    db.test.totalSize() - storage allocated for all data and indexes
    db.test.update( query, object[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi
    db.test.updateOne( filter, update, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j
    db.test.updateMany( filter, update, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j
    db.test.validate( <full> ) - SLOW
    db.test.getShardVersion() - only for use with sharding
    db.test.getShardDistribution() - prints statistics about data distribution in the cluster
    db.test.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
    db.test.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
    db.test.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
    db.test.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
    db.test.latencyStats() - display operation latency histograms for this collection

本文作者:前端首席體驗師(CheongHu)
聯(lián)系郵箱:simple2012hcz@126.com
版權(quán)聲明: 本文章除特別聲明外捌臊,均采用 CC BY-NC-SA 4.0 許可協(xié)議。轉(zhuǎn)載請注明出處秽誊!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市琳骡,隨后出現(xiàn)的幾起案子锅论,更是在濱河造成了極大的恐慌,老刑警劉巖楣号,帶你破解...
    沈念sama閱讀 219,110評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件最易,死亡現(xiàn)場離奇詭異,居然都是意外死亡炫狱,警方通過查閱死者的電腦和手機藻懒,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,443評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來视译,“玉大人嬉荆,你說我怎么就攤上這事】岷” “怎么了鄙早?”我有些...
    開封第一講書人閱讀 165,474評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長椅亚。 經(jīng)常有香客問我限番,道長,這世上最難降的妖魔是什么呀舔? 我笑而不...
    開封第一講書人閱讀 58,881評論 1 295
  • 正文 為了忘掉前任弥虐,我火速辦了婚禮,結(jié)果婚禮上媚赖,老公的妹妹穿的比我還像新娘躯舔。我一直安慰自己,他們只是感情好省古,可當我...
    茶點故事閱讀 67,902評論 6 392
  • 文/花漫 我一把揭開白布粥庄。 她就那樣靜靜地躺著,像睡著了一般豺妓。 火紅的嫁衣襯著肌膚如雪惜互。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,698評論 1 305
  • 那天琳拭,我揣著相機與錄音训堆,去河邊找鬼。 笑死白嘁,一個胖子當著我的面吹牛坑鱼,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,418評論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼鲁沥,長吁一口氣:“原來是場噩夢啊……” “哼呼股!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起画恰,我...
    開封第一講書人閱讀 39,332評論 0 276
  • 序言:老撾萬榮一對情侶失蹤彭谁,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后允扇,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體缠局,經(jīng)...
    沈念sama閱讀 45,796評論 1 316
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,968評論 3 337
  • 正文 我和宋清朗相戀三年考润,在試婚紗的時候發(fā)現(xiàn)自己被綠了狭园。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,110評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡糊治,死狀恐怖唱矛,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情俊戳,我是刑警寧澤,帶...
    沈念sama閱讀 35,792評論 5 346
  • 正文 年R本政府宣布馆匿,位于F島的核電站抑胎,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏渐北。R本人自食惡果不足惜阿逃,卻給世界環(huán)境...
    茶點故事閱讀 41,455評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望赃蛛。 院中可真熱鬧恃锉,春花似錦、人聲如沸呕臂。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,003評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽歧蒋。三九已至土砂,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間谜洽,已是汗流浹背萝映。 一陣腳步聲響...
    開封第一講書人閱讀 33,130評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留阐虚,地道東北人序臂。 一個月前我還...
    沈念sama閱讀 48,348評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像实束,于是被迫代替她去往敵國和親奥秆。 傳聞我的和親對象是個殘疾皇子逊彭,可洞房花燭夜當晚...
    茶點故事閱讀 45,047評論 2 355

推薦閱讀更多精彩內(nèi)容