MongoDB 学习笔记(一)

windows启动MongoDB :cmd进入到安装目录(D:\mongodb\bin)

mongod --dbpath D:\MongoDB\data\db

新开cmd 进入D:\mongodb\bin 输入mongo成功启动页面:


连接到指定机器名和端口:

mongo host:port/DB(如:mongo 192.168.1.2:27017/myDB)

或者启动mongo时候不连接数据库,需要时在运行new Mongo(hostname)就可以连接指定数据库

mongo --npdb

>conn = new Mongo("192.168.1.2:27017")

>db = conn.getDB("myDB")

基本命令:输入help显示常用命令

        db.help()                    help on db methods
        db.mycoll.help()             help on collection methods
        sh.help()                    sharding helpers
        rs.help()                    replica set helpers
        help admin                   administrative help
        help connect                 connecting to a db help
        help keys                    key shortcuts
        help misc                    misc things to know
        help mr                      mapreduce


        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
        show logs                    show the accessible logger names
        show log [name]              prints out the last segment of log in memory, 'global' is default
        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 further iterate
        DBQuery.shellBatchSize = x   set default number of items to display on shell
        exit                         quit the mongo shell

其他常用命令:

db.version()显示当前db版本

db.getName()查看当前使用的数据库

数据库命令:

插入数据: db.foo.save({name: "'swain'", age: 26, sex: true});

查找数据:db.foo.find();

删除数据:db.foo.drop();



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值