开发者

In Node.js Mongoose, I want to update each field...how can I do that?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜