MongoDB_01

下载安装MongoDB

  1. 从官网下载windows版mongodb
  2. 安装
  3. 配置环境变量
  4. 在管理员命令行中创建DB指定存放路径及日志路径
  5. 在计算机管理中启动MongoDB服务
  6. 用mongo命令连接到DB
----------------
C:\WINDOWS\system32>mongod --dbpath=D:\developer\mongo\db\ --logpath=D:\developer\mongo\log.txt --install
2017-10-13T00:15:51.173+0800 I CONTROL  [main] log file "D:\developer\mongo\log.txt" exists; moved to "D:\developer\mongo\log.txt.2017-10-12T16-15-51".
-------------------
C:\WINDOWS\system32>mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.9
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-10-13T00:17:59.907+0800 I CONTROL  [initandlisten]
2017-10-13T00:17:59.908+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-13T00:17:59.908+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-10-13T00:17:59.908+0800 I CONTROL  [initandlisten]
>

常用操作

  1. 查看当前库名称 db.getName()
  2. 创建数据库 use 数据库名
  3. 查看数据库状态 db.stats()
  4. 简单计算
  5. 使用db.help()查看帮助信息
> db.getName()
test
> use mark
switched to db mark
> db.getName()
mark
>
> db.stats()
{
        "db" : "mark",
        "collections" : 0,
        "views" : 0,
        "objects" : 0,
        "avgObjSize" : 0,
        "dataSize" : 0,
        "storageSize" : 0,
        "numExtents" : 0,
        "indexes" : 0,
        "indexSize" : 0,
        "fileSize" : 0,
        "ok" : 1
}
>
> x=100
100
> y=200
200
> x+y
300
> x-y
-100
> x*y
20000
> x/y
0.5
>

简单插入及查询

> db.goods.insert({name:'xiaomi',price:2300})
WriteResult({ "nInserted" : 1 })

> db.goods.find()
{ "_id" : ObjectId("59df99b3e100dab601c2522a"), "name" : "xiaomi", "price" : 2300 }
>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值