tym*_*eJV 10
改变这一行:
({_id:doc._id},$set:{scores:zz});
Run Code Online (Sandbox Code Playgroud)
至:
({_id:doc._id}, { $set:{scores:zz}} );
Run Code Online (Sandbox Code Playgroud)
这也应该用回调包装,以捕获错误:
db.schools.update({_id:doc._id}, {$set:{scores:zz}}, function(err, result) {
if (err)
//do something.
});
Run Code Online (Sandbox Code Playgroud)
I know it's a bit late to help you now, but maybe others can benefit as new cohorts pass through MongoDB University!
db.schools.update should read db.students.update.
@tymeJV's answer gives the rest:
$set inside braces: {$set:{scores:zz}}Add a callback function to catch errors:
db.collection( 'students' ).update (
{ _id : doc._id },
{ $set : { scores:zz } },
function( err, result ) {
if ( err ) throw err;
}
);
Run Code Online (Sandbox Code Playgroud)Funnily enough, I'm actually doing exactly the same assignment right now! I had a different issue that was answered by reading the docs, but I saw this question while googling for it. Hope I helped someone!
| 归档时间: |
|
| 查看次数: |
43699 次 |
| 最近记录: |