一、 在 MongoDB Compass中输入条件查询数据

{"src":"小车"}           // = 该值

{"src":{$eq:null}}      //$eq 即 ==

{"src":{$eq:null},"timeout":{$ne:1}}  //复合条件 , $ne 即 !=

{"name": {$regex:/粉/}}  //正则表达式: 本例相当于  like "%粉%"

 
二、 在本地导出导入 mongoDB数据表 (cmd或shell中)
如果是在windows中 ,需要设置环境变量(系统变量path 中添加 MongoDb的bin目录 如C:\Program Files\MongoDB\Server\4.2\bin)
1. 将数据库jijiu 的表99_category  导出至本机的  E:/99_category.json
mongoexport -h 127.0.0.1 -d jijiu -c 99_category -o E:/99_category.json
 
2. (1的反向操作)将json导入数据表
mongoimport -d jijiu -c 99_category --file E:/99_category.json
 
三、创建删除数据库以及查询 (cmd 或shell中)
mongo --host localhost:27017   //连接本地MongoDB
show dbs //显示有哪些数据库
use exampledb  //切换到或创建 数据库  exampledb,,如果什么都不操作离开的话,这个库就会被系统删除.所以我们还要执行下面的命令:
db.Apple.insert({"name":"apple","price":3.5}) //这样在数据库exampledb  中创建了一张名为Apple的表并在其中插入一条记录
show collections //显示有哪些表
db.position.find({"uid":35,"timestamp":{"$gt":1602681600,"$lt":1602682800}}).sort({"timestamp":-1})   //查询语句  其中$gt : > ,$lt <  。sort -1代表倒序
db.position.find({"uid":27}).sort({"timestamp":-1})
db.dropDatabase()     // 删除该库
exit      //退出mongoshell
 
 
 
posted on 2022-05-13 22:19  逆风向阳  阅读(212)  评论(0)    收藏  举报