我的Mongo DB Collection中有以下内容
我需要能够将阿森纳的积分更新为等于巴塞罗那的积分。我见过的任何视频教程似乎都没有提供这样的基本功能。
我认为这可以在Mongo DB中使用吗?
db.teams.insert({
team_id: "spa1",
date_founded: new Date("Oct 04, 1912"),
league: "La Liga",
points: 80,
name: "Barcelona",
players: [ { p_id: "Messi", goal: 195, caps: 189, age: 30 },
{ p_id: "Valdes", goal: 0, caps: 158, age: 27 },
{ p_id: "Iniesta", goal: 72, caps: 25, age: 31},
{ p_id: "Pique", goal: 9, caps: 201, age: 38 } ]
});
db.teams.insert({
team_id: "eng2",
date_founded: new Date("Oct 04, 1899"),
league: "Premier League",
points: 52,
name: "Arsenal",
players: [ { p_id: "Mata", goal: 5, caps: 24, age: 27 },
{ p_id: "Bergkamp", goal: 95, caps: 98, age: 48 } ]
});
答案 0 :(得分:0)
您可以使用两个单独的查询执行此操作:
// find the barcelona document first
var cursor = db.teams.find({team_id: "spa1"});
var barcelona = cursor.next();
// set the arsenal points equal to barcelona ones
db.teams.update({team_id: "eng2"}, {$set: {"points": barcelona.points}});