zoukankan      html  css  js  c++  java
  • mongoDB数据库文件路径和数据操作

    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":70});
    
    多个条件:
    db.student.find({"score.shuxue":70 , "age":12})
    
    大于条件:
    db.student.find({"score.yuwen":{$gt:50}});
    
    或者。寻找所有年龄是9岁,或者11岁的学生 
    db.student.find({$or:[{"age":9},{"age":11}]});
    
    查找完毕之后,打点调用sort,表示升降排序。
    db.restaurants.find().sort( { "borough": 1, "address.zipcode": 1 } )

    6、修改数据:

    修改里面还有查询条件。要该谁,要告诉mongo。
    db.student.update({"name":"小明"},{$set:{"age":16}});
    
    查找数学成绩是70,把年龄更改为33岁:
    db.student.update({"score.shuxue":70},{$set:{"age":33}});
    
    更改所有匹配项目:"
    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":33}},{multi: true});
    
    完整替换,不出现$set关键字了:
    db.student.update({"name":"小明"},{"name":"大明","age":16});

    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 } )
  • 相关阅读:
    针对Ext js的分页存储过程适用于sqlserver2008
    30分钟LINQ教程
    windows server 2003 sp2安装VS2010之后需要打的几个布丁
    【翻译】Prism4:初始化Prism应用程序(上)
    ASP.NET WebAPI 路由规则与POST数据
    基于.net开发chrome核心浏览器【二】
    六种SQL Server删除重复行的方法
    Web在线操作Office文件 (转)
    ASP.NET 中如何对生成的 HTML 内容流进行控制?
    使用键值表实现通用流水号(转)
  • 原文地址:https://www.cnblogs.com/angelatian/p/11005332.html
Copyright © 2011-2022 走看看