[Mongodb] 3.使用mongodb -----------使用compass
·
-
创建一个数据库:点’create database’

comment1:相当于一个项目
users:相当于一个表 -
在comment1中新建一个表:comments: 点’create collection’

-
在users中添加数据
- 在users表中点击 ‘Insert Document’

2)输入json格式的数据:

3)插入数据:点击insert后,如下( _id自动生成,保证数据的唯一性)

- 在users表中点击 ‘Insert Document’
-
查询数据:查询city是beijing的数据
- 在filter中输入{city: ‘beijing’}
2)点击find,即可查找

- 在filter中输入{city: ‘beijing’}
-
查询数据(多条件 city:shanghai, username: ‘zhangsan’):
1)在filter中输入{city: ‘shanghai’, username: ‘zhangsan’}- 点击find,即可查找
-
排序
1)点开‘OPTIONS’

2)在SORT 输入要按照什么字段排序,如果值为正,则为正序,值为负,则为倒叙。如:按年龄倒叙

更多推荐
所有评论(0)