User.find({},function(err,docs){
foreach(docs as d){
d.name="apple";
d.save();
};
});
This doesn't work! I get some "unique identifier" error. Can someone fix this for me?
User.find({},function(err,docs){
foreach(docs as d){
d.name="apple";
d.save();
};
});
This doesn't work! I get some "unique identifier" error. Can someone fix this for me?
Share Improve this question edited Sep 22, 2017 at 17:57 CommunityBot 11 silver badge asked Apr 27, 2011 at 18:06 TIMEXTIMEX 273k368 gold badges802 silver badges1.1k bronze badges 1-
not knowing anything about mongoose and only just today saw a demo of Node, perhaps giving all your docs the name "apple" is not right? Can you do
d.name="apple"+(i++);
and definevar i=0
before the foreach? Or are you talking about search.cpan/dist/Mongoose/lib/Mongoose/Intro.pod#_id – mplungjan Commented Apr 27, 2011 at 18:21
2 Answers
Reset to default 6I 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744724284a4590089.html
评论列表(0条)