我的数据库集合:
获奖者:
{
"_id": {
"$oid": "5bd58921fb6fc074abb12ce8"
},
"id": "301",
"winner": [
"101",
"102"
]
}
这是收藏家赢家的榜样
var Schema = mongoose.Schema;
var winner = new Schema({
_id: String,
id: String,
winner:[ String ]
},
{
strict: false
});
var Winner = mongoose.model('winner', winner);
var data = [ { _id: 5bd587adfb6fc074abb12cb2,
name: 'name 1',
year: '3',
id: '101' },
{ _id: 5bd587cffb6fc074abb12cb8,
name: 'name 2',
year: '4',
id: '102' } ];
Winner.update("101":data, function(err, result){
console.log(result);
});
将数据变量中的值更新为与id字段匹配的获胜者集合数组(即,值101应该由具有id字段“ id”的值的数据变量中的json更新) :“ 101”
输出应为
优胜者收藏集应更新为
获奖者:
{
"_id": {
"$oid": "5bd58921fb6fc074abb12ce8"
},
"id": "301",
"winner": [
{ _id: 5bd587adfb6fc074abb12cb2,
name: 'name 1',
year: '3',
id: '101' },
{ _id: 5bd587cffb6fc074abb12cb8,
name: 'name 2',
year: '4',
id: '102' }
]
}
先谢谢了:)