(3) mongodb data add, modify, delete

1, the data added

  Add a data, json format.

    db.goods.insert({name:'电脑',price:5600,goods_num:'00001',click_num:1});

    db.goods.insert({_id:1,name:'苹果',color:'red',price:12});

  Add pieces of data, json array.

    db.goods.insert ([{type: 'pot', name: 'pan', price: 300}, {_ id: 2, name: 'fish', num: 304}]);

  Note that if there is no json _id column will generate a default _id, _id specified time can not be repeated, collection of unique _id.

  The following are four data insertion:

  { "_id" : ObjectId("5d3efadd7dc39a8207a088c4"), "name" : "电脑", "price" : 5600, "goods_num" : "00001", "click_num" : 1 }
  { "_id" : 1, "name" : "苹果", "color" : "red", "price" : 12 }
  { "_id" : ObjectId("5d3efcf97dc39a8207a088c7"), "type" : "锅", "name" : "平底锅", "price" : 300 }
  { "_id" : 2, "name" : "鱼", "num" : 304 }

Guess you like

Origin www.cnblogs.com/javasl/p/11266876.html