MongoDB帮助信息:db方法,collection方法

本文涉及的产品
云数据库 MongoDB,通用型 2核4GB
简介:

2000元阿里云代金券免费领取,2核4G云服务器仅664元/3年,新老用户都有优惠,立即抢购>>>


阿里云采购季(云主机223元/3年)活动入口:请点击进入>>>,


阿里云学生服务器(9.5元/月)购买入口:请点击进入>>>,

 

 
  1. mongos> db.help()  
  2. DB methods:  
  3.         db.addUser(username, password[, readOnly=false])  
  4.         db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]  
  5.         db.auth(username, password)  
  6.         db.cloneDatabase(fromhost)  
  7.         db.commandHelp(name) returns the help for the command  
  8.         db.copyDatabase(fromdb, todb, fromhost)  
  9.         db.createCollection(name, { size : ..., capped : ..., max : ... } )  
  10.         db.currentOp() displays currently executing operations in the db  
  11.         db.dropDatabase()  
  12.         db.eval(func, args) run code server-side  
  13.         db.fsyncLock() flush data to disk and lock server for backups  
  14.         db.fsyncUnlock() unlocks server following a db.fsyncLock()  
  15.         db.getCollection(cname) same as db['cname'] or db.cname  
  16.         db.getCollectionNames()  
  17.         db.getLastError() - just returns the err msg string  
  18.         db.getLastErrorObj() - return full status object  
  19.         db.getMongo() get the server connection object  
  20.         db.getMongo().setSlaveOk() allow queries on a replication slave server  
  21.         db.getName()  
  22.         db.getPrevError()  
  23.         db.getProfilingLevel() - deprecated  
  24.         db.getProfilingStatus() - returns if profiling is on and slow threshold  
  25.         db.getReplicationInfo()  
  26.         db.getSiblingDB(name) get the db at the same server as this one  
  27.         db.hostInfo() get details about the server's host  
  28.         db.isMaster() check replica primary status  
  29.         db.killOp(opid) kills the current operation in the db  
  30.         db.listCommands() lists all the db commands  
  31.         db.loadServerScripts() loads all the scripts in db.system.js  
  32.         db.logout()  
  33.         db.printCollectionStats()  
  34.         db.printReplicationInfo()  
  35.         db.printShardingStatus()  
  36.         db.printSlaveReplicationInfo()  
  37.         db.removeUser(username)  
  38.         db.repairDatabase()  
  39.         db.resetError()  
  40.         db.runCommand(cmdObj) run a database command.  if cmdObj is a string, turns it into { cmdObj : 1 }  
  41.         db.serverStatus()  
  42.         db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all  
  43.         db.setVerboseShell(flag) display extra information in shell output  
  44.         db.shutdownServer()  
  45.         db.stats()  
  46.         db.version() current version of the server  
  47. mongos> 

 

 
  1. mongos> db.myCollection.help()  
  2. DBCollection help  
  3.         db.myCollection.find().help() - show DBCursor help  
  4.         db.myCollection.count()  
  5.         db.myCollection.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.  
  6.         db.myCollection.convertToCapped(maxBytes) - calls {convertToCapped:'myCollection', size:maxBytes}} command  
  7.         db.myCollection.dataSize()  
  8.         db.myCollection.distinct( key ) - e.g. db.myCollection.distinct( 'x' )  
  9.         db.myCollection.drop() drop the collection  
  10.         db.myCollection.dropIndex(index) - e.g. db.myCollection.dropIndex( "indexName" ) or db.myCollection.dropIndex( { "indexKey" : 1 } )  
  11.         db.myCollection.dropIndexes()  
  12.         db.myCollection.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups  
  13.         db.myCollection.reIndex()  
  14.         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} )  
  15.         db.myCollection.find(...).count()  
  16.         db.myCollection.find(...).limit(n)  
  17.         db.myCollection.find(...).skip(n)  
  18.         db.myCollection.find(...).sort(...)  
  19.         db.myCollection.findOne([query])  
  20.         db.myCollection.findAndModify( { update : ... , remove : bool [, query:{}, sort: {}, 'new'false] } )  
  21.         db.myCollection.getDB() get DB object associated with collection  
  22.         db.myCollection.getIndexes()  
  23.         db.myCollection.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )  
  24.         db.myCollection.insert(obj)  
  25.         db.myCollection.mapReduce( mapFunction , reduceFunction , <optional params> )  
  26.         db.myCollection.remove(query)  
  27.         db.myCollection.renameCollection( newName , <dropTarget> ) renames the collection.  
  28.         db.myCollection.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name  
  29.         db.myCollection.save(obj)  
  30.         db.myCollection.stats()  
  31.         db.myCollection.storageSize() - includes free space allocated to this collection  
  32.         db.myCollection.totalIndexSize() - size in bytes of all the indexes  
  33.         db.myCollection.totalSize() - storage allocated for all data and indexes  
  34.         db.myCollection.update(query, object[, upsert_bool, multi_bool]) - instead of two flags, you can pass an object with fields: upsert, multi  
  35.         db.myCollection.validate( <full> ) - SLOW  
  36.         db.myCollection.getShardVersion() - only for use with sharding  
  37.         db.myCollection.getShardDistribution() - prints statistics about data distribution in the cluster  
  38.         db.myCollection.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function 

 



 本文转自 hexiaini235 51CTO博客,原文链接:http://blog.51cto.com/idata/1098084,如需转载请自行联系原作者


相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。 &nbsp; 相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
相关文章
|
5天前
|
NoSQL 关系型数据库 MySQL
深入了解 Python MongoDB 查询:find 和 find_one 方法完全解析
在 MongoDB 中,我们使用 find() 和 find_one() 方法来在集合中查找数据,就像在MySQL数据库中使用 SELECT 语句来在表中查找数据一样
67 1
|
9月前
|
SQL NoSQL Shell
MongoDB常用的操作-(find方法)
MongoDB常用的操作-(find方法)
146 0
|
NoSQL MongoDB 数据库
4种方法解决MongoDB游标超时的问题
4种方法解决MongoDB游标超时的问题
464 0
|
NoSQL Java MongoDB
MongoDB Limit与Skip方法
MongoDB Limit与Skip方法
57 0
|
存储 NoSQL JavaScript
使用TS封装操作MongoDB数据库的工具方法
使用TS封装操作MongoDB数据库的工具方法
|
存储 NoSQL 关系型数据库
MongoDB(4)- Collection 集合相关
MongoDB(4)- Collection 集合相关
137 0
MongoDB(4)- Collection 集合相关
|
缓存 NoSQL MongoDB
MongoDB:5-MongoDB的固定集合(capped collection)
MongoDB:5-MongoDB的固定集合(capped collection)
154 0
|
NoSQL MongoDB
MongoDB实现Multi tenant的方法
MongoDB实现Multi tenant的方法
232 0
MongoDB实现Multi tenant的方法
HDM
|
Web App开发 监控 NoSQL
MongoDB负载信息一目了然 阿里云HDM重磅发布MongoDB监控和诊断功能
混合云数据库管理(HDM)的监控和诊断功能新增了对MongoDB的支持。 通过直观的方式将MongoDB多个维度的负载信息统一整合,不仅可以清晰的查看实时负载信息,也可以方便的确认历史负载情况,同时也支持自定义性能监控大盘。
HDM
3975 0
|
监控 NoSQL 数据库
mongodb监控常用方法
列举mongodb监控的常用命令 1.监控统计 mongostat 可用于查看当前QPS/内存使用/连接数,以及多个shard的压力分布 命令参考 ./mongostat --port 27071 -u admin -p xxx --authenticationDatabase=admin --d...
1658 0
http://www.vxiaotou.com