pond2539 发表于 2018-10-24 11:08:11

大数据必备的数据库 MongoDB 3.6 安装、单机多实例和基本操作

mongos> db.test.insert({"id":1,"name":"zhangsan"})   #在test集合插入数据没有test集合默认会自动创建  WriteResult({ "nInserted" : 1 })
  mongos> db.test.insert({"id":2,"name":"lisi"})
  WriteResult({ "nInserted" : 1 })
  mongos> db.test.find()                           #查看集合内容
  { "_id" : ObjectId("5b4eb95659122739e2695613"), "id" : 1, "name" : "zhangsan" }
  { "_id" : ObjectId("5b4eb96759122739e2695614"), "id" : 2, "name" : "lisi" }
  mongos> db.test.remove({"id":1})      #删除test集合中的id为1的数据
  WriteResult({ "nRemoved" : 1 })
  mongos> db.test.find()
  { "_id" : ObjectId("5b4eb96759122739e2695614"), "id" : 2, "name" : "lisi" }
  mongos> db.test.update({"id":2},{$set:{"name":"wangwu"}})    #修改数据
  WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  mongos> db.test.find()
  { "_id" : ObjectId("5b4eb96759122739e2695614"), "id" : 2, "name" : "wangwu" }

页: [1]
查看完整版本: 大数据必备的数据库 MongoDB 3.6 安装、单机多实例和基本操作