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 } )

最新文章

  1. C#对DBF文件的操作
  2. C语言中extern的用法
  3. 根目录97 <input file>标签,把图片上传到服务器(跟增删改查一起实现)
  4. MAT内存问题分析定位
  5. C 封装一个简单二叉树基库
  6. [原创]HTML5 web性能监控策略
  7. windows nfs server for linux
  8. notepad++ 配置笔记
  9. 整理了一份React-Native学习指南
  10. MySQL .msi 安装失败改用.zip安装步骤
  11. Android学习笔记2——shape
  12. 将 Net 项目升级 Core项目经验:(三)迁移后的Net Standard版本的类库测试和多平台项目实测
  13. python学习第9-10天,函数。
  14. 基于Fragment的插件化
  15. Android View体系(四)从源码解析Scroller
  16. Java中Dom解析XML
  17. PHP 将大量数据导出到 Excel 的方法
  18. Django Celery定时任务和时间设置
  19. bootstrap fileinput 文件上传
  20. 微信小程序——加入购物车弹层

热门文章

  1. String.format保留小数位数
  2. 关于Sass和Less牵扯的问题
  3. python基础_0623
  4. python内存泄露memory leak排查记录
  5. GitHub:Youtube
  6. Spring Bean学习创建及使用<一>
  7. jsp页面中使用javabean
  8. Ceph RBD 的实现原理与常规操作
  9. linux常用命令(19)find xargs
  10. linux之文件操作和权限