User.find({},function(err,docs){
foreach(docs as d){
d.name="apple";
d.sav开发者_运维问答e();
};
});
This doesn't work! I get some "unique identifier" error. Can someone fix this for me?
I think you're using foreach incorrectly. Try replacing the contents of your callback with this:
docs.forEach(function(elem, index, array) {
elem.name = "apple";
elem.save();
});
Check out the MDC for more information on foreach.
Does d
have a unique index set? If so you will be unable to set the same thing for multiple instances.
精彩评论