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 command db.copyDatabase(fromdb, todb, fromhost) db.createCollection(name, { size : ..., capped : ..., max : ... } ) db.currentOp() displays currently executing operations in the db db.dropDatabase() db.eval(func, args) run code server-side db.fsyncLock() flush data to disk and lock server for backups db.fsyncUnlock() unlocks server following a db.fsyncLock() db.getCollection(cname) same as db['cname'] or db.cname db.getCollectionNames() db.getLastError() - just returns the err msg string db.getLastErrorObj() - return full status object db.getMongo() get the server connection object db.getMongo().setSlaveOk() allow queries on a replication slave server db.getName() db.getPrevError() db.getProfilingLevel() - deprecated db.getProfilingStatus() - returns if profiling is on and slow threshold db.getReplicationInfo() db.getSiblingDB(name) get the db at the same server as this one db.hostInfo() get details about the server's host db.isMaster() check replica primary status db.killOp(opid) kills the current operation in the db db.listCommands() lists all the db commands db.loadServerScripts() loads all the scripts in db.system.js db.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,<slowms>) 0=off 1=slow 2=all db.setVerboseShell(flag) display extra information in shell output db.shutdownServer() db.stats() db.version() current version of the server mongos>
mongos> db.myCollection.help() DBCollection help db.myCollection.find().help() - show DBCursor help db.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}} command db.myCollection.dataSize() db.myCollection.distinct( key ) - e.g. db.myCollection.distinct( 'x' ) db.myCollection.drop() drop the collection db.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, dropDups db.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( {x:77} , {name:1, x: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() get DB object associated with collection db.myCollection.getIndexes() db.myCollection.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } ) db.myCollection.insert(obj) db.myCollection.mapReduce( mapFunction , reduceFunction , <optional params> ) db.myCollection.remove(query) db.myCollection.renameCollection( newName , <dropTarget> ) renames the collection. db.myCollection.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name db.myCollection.save(obj) db.myCollection.stats() db.myCollection.storageSize() - includes free space allocated to this collection db.myCollection.totalIndexSize() - size in bytes of all the indexes db.myCollection.totalSize() - storage allocated for all data and indexes db.myCollection.update(query, object[, upsert_bool, multi_bool]) - instead of two flags, you can pass an object with fields: upsert, multi db.myCollection.validate( <full> ) - SLOW db.myCollection.getShardVersion() - only for use with sharding db.myCollection.getShardDistribution() - prints statistics about data distribution in the cluster db.myCollection.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。