MongoDBデータを挿入3つの方法

1.insert()方法
db.inventory.insert( { _id: 10, type: “misc", item: “card", qty: 15 } )

2.update()方法
db.inventory.update(
{ type: “book", item : “journal" },
{ $set : { qty: 10 } },
{ upsert :true }
)
_idカラムと唯一Objectidを追加
{ “_id" : ObjectId(“51e8636953dbe31d5f34a38a"), “item" : “journal", “qty" : 10, “type" : “book" }
3.save()方法
db.inventory.save( { type: “book", item: “notebook", qty: 40 } )

_idカラムと唯一のObjectIdを追加
{ “_id" : ObjectId(“51e866e48737f72b32ae4fbc"), “type" : “book", “item" : “notebook", “qty" : 40 }

Source

Posted by arkgame