table层级的函数/方法

# 使用如下命令会显示test表级的函数/方法
db.test.help()
方法 说明
db.test.find().help() show DBCursor help
db.test.bulkWrite( operations, ) bulk execute write operations, optional parameters are: w, wtimeout, j
db.test.count( query = {}, ) count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
db.test.countDocuments( query = {}, ) count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
db.test.estimatedDocumentCount( ) estimate the document count using collection metadata, optional parameters are: maxTimeMS
db.test.convertToCapped(maxBytes) calls {convertToCapped:’test’, size:maxBytes}} command
db.test.createIndex(keypattern[,options])
db.test.createIndexes([keypatterns], )
db.test.dataSize()
db.test.deleteOne( filter, ) delete first matching document, optional parameters are: w, wtimeout, j
db.test.deleteMany( filter, ) delete all matching documents, optional parameters are: w, wtimeout, j
db.test.distinct( key, query, ) 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.hideIndex(index) e.g. db.test.hideIndex( “indexName” ) or db.test.hideIndex( { “indexKey” : 1 } )
db.test.unhideIndex(index) e.g. db.test.unhideIndex( “indexName” ) or db.test.unhideIndex( { “indexKey” : 1 } )
db.test.dropIndexes()
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, ) delete first matching document, optional parameters are: projection, sort, maxTimeMS
db.test.findOneAndReplace( filter, replacement, ) replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
db.test.findOneAndUpdate( filter, , ) 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.insert(obj)
db.test.insertOne( obj, ) insert a document, optional parameters are: w, wtimeout, j
db.test.insertMany( [objects], ) insert multiple documents, optional parameters are: w, wtimeout, j
db.test.mapReduce( mapFunction , reduceFunction , )
db.test.aggregate( [pipeline], ) performs an aggregation on a collection; returns a cursor
db.test.remove(query)
db.test.replaceOne( filter, replacement, ) replace the first matching document, optional parameters are: upsert, w, wtimeout, j
db.test.renameCollection( newName , ) renames the collection.
db.test.runCommand( name , ) 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: , indexDetailsName: })
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, [, upsert_bool, multi_bool] ) instead of two flags, you can pass an object with fields: upsert, multi, hint, let
db.test.updateOne( filter, , ) update the first matching document, optional parameters are: upsert, w, wtimeout, j, hint, let
db.test.updateMany( filter, , ) update all matching documents, optional parameters are: upsert, w, wtimeout, j, hint, let
db.test.validate( ) SLOW
db.test.getShardVersion() only for use with sharding
db.test.getShardDistribution() prints statistics about data distribution in the cluster
db.test.getSplitKeysForChunks( ) 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( ) sets the write concern for writes to the collection
db.test.unsetWriteConcern( ) unsets the write concern for writes to the collection
db.test.latencyStats() display operation latency histograms for this collection
作者:joker.liu  创建时间:2022-07-06 15:50
最后编辑:joker.liu  更新时间:2022-07-06 16:27