zoukankan      html  css  js  c++  java
  • MongoDB的数据库基本操作(一)

    查看当前数据库

    MongoDB shell version:1.8.1
    connecting to:test
    > db
    test

     

    查看全部数据库列表

    >show dbs
    ChatRoom    0.03125GB
    admin       (empty)
    local       (empty)

     

    切换数据库

    >use ChatRoom
    switched to db ChatRoom
    >db
    ChatRoom

     

    删除数据库

    >db
    ChatRoom
    >show dbs
    ChatRoom    0.03125GB
    admin       (empty)
    local       (empty)
    >db.dropDatabase()
    {
    "dropped":"ChatRoom","ok":1}
    >show dbs
    admin       (empty)
    local       (empty)

     

     MongoDB帮助主题help

    > help
            db.help()                    help on db methods
            db.mycoll.help()             help on collection methods
            rs.help()                    help on replica set methods
            help connect                 connecting to a db help
            help admin                   administrative help
            help misc                    misc things to know
            help mr                      mapreduce help

            show dbs                     show database names
            show collections             show collections 
    in current database
            show users                   show users 
    in current database
            show profile                 show most recent system.profile entries with time
    >= 1ms
            use 
    <db_name>                set current database
            db.foo.find()                list objects 
    in collection foo
            db.foo.find( { a : 
    1 } )     list objects in foo where a == 1
            it                           result of the last line evaluated; use to furtheriterate
            DBQuery.shellBatchSize 
    = x   set default number of items to display on shell
            exit                         quit the mongo shell

     

    > db.help()
    DB methods:
            db.addUser(username, password[, readOnly
    =false])
            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 the current operation 
    in the db
            db.dropDatabase()
            db.eval(func, args) run code server
    -side
            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 this connection to read 
    from the nonmaster member of a replica pair
            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.isMaster() check replica primary status
            db.killOp(opid) kills the current operation 
    in the db
            db.listCommands() lists all the db commands
            db.printCollectionStats()
            db.printReplicationInfo()
            db.printSlaveReplicationInfo()
            db.printShardingStatus()
            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.shutdownServer()
            db.stats()
            db.version() current version of the server
            db.getMongo().setSlaveOk() allow queries on a replication slave server
  • 相关阅读:
    微信公众账号报错 返回码说明
    2013与2014之流水
    【Leetcode刷题】字符串模式匹配算法知多少
    【数据库测试工具】认识Sysbench
    【论文笔记】《基于深度学习的中文命名实体识别研究》阅读笔记
    分享一份关于Hadoop2.2.0集群环境搭建文档
    【Java实践】Kettle从一次实验说起
    【资源共享】eBook分享大集合
    java入门知识
    python编程规范系列--建议08~18
  • 原文地址:https://www.cnblogs.com/wuxiang/p/4626789.html
Copyright © 2011-2022 走看看