MongoDB 相关的一些操作
2024-09-08 17:45:08
一、 在 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
详见菜鸟教程之MongoDB:https://www.runoob.com/mongodb/mongodb-query.html
最新文章
- 如果用css的border属性画一个三角形
- EF Code First 主键对应多个外键
- [调整] Firemonkey TEdit 避免按下立即弹出键盘的问题
- Rootkit Hunter恶意程序查杀
- if -else 条件语句原理
- [IR] Probabilistic Model
- [PE结构分析] 9.导出表 IMAGE_EXPORT_DIRECTORY
- JS生成UUID的方法实例
- mantis 安装问题
- MVC项目发布错误
- android开发,关于android app实现静默安装自己(系统签名)
- delphi定义自己的消息
- (二)《Java编程思想》——t h i s 关键字
- 送给刚刚開始学cocos2d-x引擎 移植Android的同学
- [ An Ac a Day ^_^ ] CodeForces 586C Gennady the Dentist 模拟
- Activiti-05-.Deployment and MN 2.0 Introduction
- Linuxc - 多c文件程序编译执行
- API Gateway性能比较:NGINX vs. ZUUL vs.Cloud Gateway vs. Linkerd[译]
- 2018 UESTC 线段树专题
- vector的 []
热门文章
- 关于安装hadoop时在centos上修改主机名总是不成功
- ESXI密码正确无法登录
- Unity 动态加载图片出现红色问号
- macOS Big Sur 设置JAVA_HOME
- css 特殊性 权重排列
- anr查看的一种方法
- Flutter statecontroller.update(MaterialState.disabled,false)无效
- Centos安装后出现please make your choice from &#39;1&#39; to eter the license information spoke | &#39;q&#39; to quit |&#39;c&#39; to continue |&#39;r&#39; to refresh
- AES可以加密成
- Finance财务软件(如何运行该软件)