Open wangming1993 opened 8 years ago
var graphics = db.graphic.find({"accountId":ObjectId("55e44579971374c40a8b4566")}) graphics.forEach(function(g){ var articles = g.articles; var newArticles = []; var isNeedUpdate = false; articles.forEach(function(a){ var newArticle = a; if ("showCoverPic" in a ) { //print("exist showCoverPic"); } else { print("add showCoverPic") newArticle.showCoverPic = true; isNeedUpdate = true; } newArticles.push(newArticle); }) if (isNeedUpdate) { print(g._id); print("need update"); db.graphic.update({"_id":g._id}, {"$set":{"articles": newArticles}}); } });