mongoDB数据库文件路径和数据操作
2024-09-03 21:50:14
1、查看MongoDB在电脑上的安装路径
which mongod
2、默认mongodb 数据文件是放到根目录 data/db 文件夹下,如果没有这个文件,需要自行创建
mkdir -p /data/db
3、或者,也可以在每次启动时指定数据库路径:
mongod --dbpath /usr/local/db
4、插入数据:
db.student.insert({"name":"xiaoming"});
5、查询数据的方法:
查找数据,用find。find中没有参数,那么将列出这个集合的所有文档:
db.restaurants.find() 精确匹配:
db.student.find({"score.shuxue":}); 多个条件:
db.student.find({"score.shuxue": , "age":}) 大于条件:
db.student.find({"score.yuwen":{$gt:}}); 或者。寻找所有年龄是9岁,或者11岁的学生
db.student.find({$or:[{"age":},{"age":}]}); 查找完毕之后,打点调用sort,表示升降排序。
db.restaurants.find().sort( { "borough": , "address.zipcode": } )
6、修改数据:
修改里面还有查询条件。要该谁,要告诉mongo。
db.student.update({"name":"小明"},{$set:{"age":}}); 查找数学成绩是70,把年龄更改为33岁:
db.student.update({"score.shuxue":},{$set:{"age":}}); 更改所有匹配项目:"
By default, the update() method updates a single document. To update multiple documents, use the multi option in the update() method.
db.student.update({"sex":"男"},{$set:{"age":}},{multi: true}); 完整替换,不出现$set关键字了:
db.student.update({"name":"小明"},{"name":"大明","age":});
7、删除数据
db.restaurants.remove( { "borough": "Manhattan" } ) By default, the remove() method removes all documents that match the remove condition. Use the justOne option to limit the remove operation to only one of the matching documents.
db.restaurants.remove( { "borough": "Queens" }, { justOne: true } )
最新文章
- C#对DBF文件的操作
- C语言中extern的用法
- 根目录97 <;input file>;标签,把图片上传到服务器(跟增删改查一起实现)
- MAT内存问题分析定位
- C 封装一个简单二叉树基库
- [原创]HTML5 web性能监控策略
- windows nfs server for linux
- notepad++ 配置笔记
- 整理了一份React-Native学习指南
- MySQL .msi 安装失败改用.zip安装步骤
- Android学习笔记2——shape
- 将 Net 项目升级 Core项目经验:(三)迁移后的Net Standard版本的类库测试和多平台项目实测
- python学习第9-10天,函数。
- 基于Fragment的插件化
- Android View体系(四)从源码解析Scroller
- Java中Dom解析XML
- PHP 将大量数据导出到 Excel 的方法
- Django Celery定时任务和时间设置
- bootstrap fileinput 文件上传
- 微信小程序——加入购物车弹层