Get the App
SLTechnology News&Howtos  ›  Database  › 

MongoDB help information: db method, collection method

Shulou Source: shulou.com Published: 2022-06-01 17:34:55 11月14日 Update

Mongos > db.help () DB methods:db.addUser (username, password [, readOnly=false]) db.adminCommand (nameOrDocument)-switches to 'admin' db, and runs command [just calls db.runCommand (...)] db.auth (username, password) db.cloneDatabase (fromhost) db.commandHelp (name) returns the help for the commanddb.copyDatabase (fromdb, todb, fromhost) db.createCollection (name, {size:..., capped:. Max:...}) db.currentOp () displays currently executing operations in the dbdb.dropDatabase () db.eval (func Args) run code server-sidedb.fsyncLock () flush data to disk and lock server for backupsdb.fsyncUnlock () unlocks server following a db.fsyncLock () db.getCollection (cname) same as db ['cname'] or db.cnamedb.getCollectionNames () db.getLastError ()-just returns the err msg stringdb.getLastErrorObj ()-return full status objectdb.getMongo () get the server connection objectdb.getMongo () setSlaveOk () allow queries on a replication slave serverdb.getName () db.getPrevError () db.getProfilingLevel ()-deprecateddb. GetProfilingStatus ()-returns if profiling is on and slow thresholddb.getReplicationInfo () db.getSiblingDB (name) get the db at the same server as this onedb.hostInfo () get details about the server's hostdb.isMaster () check replica primary statusdb.killOp (opid) kills the current operation in the dbdb.listCommands () lists all the db commandsdb.loadServerScripts () loads all the scripts in db.system.jsdb.logout () db.printCollectionStats () db.printReplicationInfo () db.printShardingStatus () db.printSlaveReplicationInfo () db.removeUser (username) db RepairDatabase () db.resetError () db.runCommand (cmdObj) run a database command. If cmdObj is a string, turns it into {cmdObj: 1} db.serverStatus () db.setProfilingLevel (level,) 0=off 1=slow 2=alldb.setVerboseShell (flag) display extra information in shell outputdb.shutdownServer () db.stats () db.version () current version of the servermongos > mongos > db.myCollection.help () DBCollection helpdb.myCollection.find () help ()-show DBCursor helpdb.myCollection.count () db.myCollection.copyTo (newColl)-duplicates collection by copying all documents to newColl No indexes are copied.db.myCollection.convertToCapped (maxBytes)-calls {convertToCapped:'myCollection', size:maxBytes}} commanddb.myCollection.dataSize () db.myCollection.distinct (key)-e.g. Db.myCollection.distinct ('x') db.myCollection.drop () drop the collectiondb.myCollection.dropIndex (index)-e.g. Db.myCollection.dropIndex ("indexName") or db.myCollection.dropIndex ({"indexKey": 1}) db.myCollection.dropIndexes () db.myCollection.ensureIndex (keypattern [ Options])-options is an object with these possible fields: name, unique, dropDupsdb.myCollection.reIndex () db.myCollection.find ([query], [fields])-query is an optional query filter. Fields is optional set of fields to return. E.g. Db.myCollection.find ({name:1, x db.myCollection.find 1}) db.myCollection.find (.). Count () db.myCollection.find (.). Limit (n) db.myCollection.find (.). Skip (n) db.myCollection.find (.). Sort (...) db.myCollection.findOne ([query]) db.myCollection.findAndModify ({update:..., remove: bool [, query: {}) Sort: {}, 'new': false]}) db.myCollection.getDB () getDB object associated with collectiondb.myCollection.getIndexes () db.myCollection.group ({key:..., initial:..., reduce:... [, cond:...]}) db.myCollection.insert (obj) db.myCollection.mapReduce (mapFunction, reduceFunction,) db.myCollection.remove (query) db.myCollection.renameCollection (newName,) renames the collection.db.myCollection.runCommand (name) ) runs a db command with the given name where the first param is the collection namedb.myCollection.save (obj) db.myCollection.stats () db.myCollection.storageSize ()-includes free space allocated tot his collectiondb.myCollection.totalIndexSize ()-size in bytes of all the indexesdb.myCollection.totalSize ()-storage allocated for all data and indexesdb.myCollection.update (query, object [, upsert_bool, multi_bool])-instead of two flags, you can pass an object with fields: upsert Multidb.myCollection.validate ()-SLOWdb.myCollection.getShardVersion ()-only for use with shardingdb.myCollection.getShardDistribution ()-prints statistics about data distribution in the clusterdb.myCollection.getSplitKeysForChunks ()-calculates split points over all chunks and returns splitter function

Tags: E.g.method information help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL macOS Shulou Information NVidia Docker