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,  ) - 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.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], )
    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.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,  ) - 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,  ) - 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,  ) - 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, object[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi
    db.test.updateOne( filter, update,  ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j
    db.test.updateMany( filter, update,  ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j
    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

本文作者:前端首席体验师(CheongHu)
联系邮箱:[email protected]
版权声明: 本文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

你可能感兴趣的:(mongodb集合API)