Mongodb 增删改查查询
Mongodb CRUD Query
如何在mongodb中insert/delete/update关注json的第二层(地址和年龄)?
{
"name": "json",
"profile": {
"address": "jersey",
"age":32
}
}
假设您想将 'stuff' 集合中所有用户的年龄增加 1,您可以执行以下操作:
db.stuff.findAndModify({
query: {"name": "json"},
update: { $inc: { "profile.age": 1 }
});
要更改地址,您需要执行以下操作:
db.stuff.findAndModify({
query: {"name": "json"},
update: { "profile.address": "Blue Jays Way, Toronto" }
});
我发现 MongoDB Documentation and the (free) MongoDB University course 非常有用。
如何在mongodb中insert/delete/update关注json的第二层(地址和年龄)?
{
"name": "json",
"profile": {
"address": "jersey",
"age":32
}
}
假设您想将 'stuff' 集合中所有用户的年龄增加 1,您可以执行以下操作:
db.stuff.findAndModify({
query: {"name": "json"},
update: { $inc: { "profile.age": 1 }
});
要更改地址,您需要执行以下操作:
db.stuff.findAndModify({
query: {"name": "json"},
update: { "profile.address": "Blue Jays Way, Toronto" }
});
我发现 MongoDB Documentation and the (free) MongoDB University course 非常有用。