随笔 - 11  文章 - 0  评论 - 21  阅读 - 7561 

一、 在 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   逆风向阳  阅读(186)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结
点击右上角即可分享
微信分享提示