修改數據
修改裏面還有查詢條件。你要該誰,要告訴 mongo。
查找名字叫作小明的,把年齡更改成 16 歲:
1 db.student.update({"name":"小明"},{$set:{"age":16}});
查找數學成績是 70,把年齡更改成 33 歲:spa
1 db.student.update({"score.shuxue":70},{$set:{"age":33}});
更改全部匹配項目:"rest
By default, the update() method updates a single document. To update multiple documents, use
the multi option in the update() method. ip
1 db.student.update({"sex":"男"},{$set:{"age":33}},{multi: true});
完整替換,不出現$set 關鍵字了: 注意rem
1 db.student.update({"name":"小明"},{"name":"大明","age":16});
db.users.update({name: 'Lisi'}, {$inc: {age: 50}}, false, true);
至關於:update users set age = age + 50 where name = ‘Lisi’;
db.users.update({name: 'Lisi'}, {$inc: {age: 50}, $set: {name: 'hoho'}}, false, true);
至關於:update users set age = age + 50, name = ‘hoho’ where name = ‘Lisi’;數學
刪除數據
db.collectionsNames.remove( { "borough": "Manhattan" } )
db.users.remove({age: 132});
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 } )it