MongoDB学习笔记

 1、 创建数据库名: use blogs

2、 查看所有数据库:show dbs

3、 插入数据: db.blogs.insert({"name":"Amy"})

4、 删除数据:

方法1  

> show dbs

admin   0.000GB

blog    0.000GB

blogs   0.000GB

config  0.000GB

local   0.000GB

> use blogs

switched to db blogs

> db.blogs.drop()

true

> show dbs

admin   0.000GB

blog    0.000GB

config  0.000GB

local   0.000GB

方法2

> show dbs

admin   0.000GB

blog    0.000GB

config  0.000GB

local   0.000GB

> use blog

switched to db blog

> db.dropDatabase()

{ "dropped" : "blog", "ok" : 1 }

> show dbs

admin   0.000GB

config  0.000GB

local   0.000GB

5、 查询数据

1)查询所有数据

 > use first

switched to db first

> show dbs

admin   0.000GB

config  0.000GB

local   0.000GB

> db.first.insert({"name":"hxy"})

WriteResult({ "nInserted" : 1 })

> show dbs

admin   0.000GB

config  0.000GB

first   0.000GB

local   0.000GB

> db.first.find()

{ "_id" : ObjectId("5d4ac97db3fc12c8fd0bb6cd"), "name" : "hxy" }

(2)模糊查询数据

$lt : <  ,  $gt : >  ,  $lte : <=  ,  $gte : >=

posted @ 2019-08-08 16:41  月华君  阅读(148)  评论(0编辑  收藏  举报