您的位置:首页 > 数据库 > Mongodb

MongoDB增删改查

2015-10-21 02:19 671 查看

1.SQL与MongoDB概念映射

SQL Terms/ConceptsMongoDB Terms/Concepts
databasedatabase
tablecollection
rowdocument or BSON document
columnfield
indexindex
table joinsembedded documents and linking
primary key

Specify any unique column or column combination as primary key.

primary key

In MongoDB, the primary key is automatically set to the _idfield.

aggregation (e.g. group by)aggregation pipeline

See the SQL to Aggregation Mapping Chart.

2.建表

  先创建一张mongo表,右击已创建的数据库test,点击addcollection..





  输入Collection Name,点击ok;

3.插入数据

  在创建的表中新增列与数据,右击表选择Insert document





  点击Insert,刷新表。

4.查询数据

  右击表格,点击Find





4.1 查询日期的方式需要在{Find}框中写

  {

    "endDate":ISODate("2013-12-30T16:00:00Z")

  }
  这样才能正确匹配到日期

4.2 查询普通数据:{"age":1,"name":"aaa"}

4.3 查询大于,小于





4.4 {Find}中写where语句

  $lt:小于,$lte:小于等于,$gt:大于,$gte:大于等于,$in:在...之中,$or:或者

  ${Where}:右击表格,点击Find2,比Find多了一个where;写表达式





  where可以写函数:





4.5 排序${Sort}

  给某个字段排序升序排序{"name":1},降序{"name":-1};注:小于0表示降序,大于等于0表示升序





4.6 查询字段${Fields}





  字段的值是1表示:查出id与该字段;值为0表示:查出表中所有字段,不包括该字段

4.7 其他选项





  skip:表示跳过多少条数据,例如表中有三条,skip为2,那么只有查出一条数据

  limit:表示分页

  detail:勾上表示界面上显示${Fields}与${Sort}

5.修改数据





  $in:同时修改多条数据,mongo中日期修改需要先格式化ISODate

  mongovue执行完修改语句后,它的控制台会自动生成语句





6.删除数据

  点击Remove





  执行remove后,会弹出删除的数据条数:



7.MongoDB官方手册

https://docs.mongodb.org/manual/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: