//Add a image_count field for each article document to record the number of images that this article containsdb[' Test.articles '].find ({' title ': ' WFC Test '}). ForEach (function(thisarticle) {//This is going to be forced to reshape, or it will become a floating point //to use Numberint to convert to shaping, use parseint to get the remaining floating-point numberImagecount = Numberint (thisarticle[' article_images '].length) db[' Test.articles '].update ({' _id ': thisarticle[' _id '}, {$set: {' Image_count '): Imagecount}} ) })//a more streamlined and able-to-do notationDb.test.articles.find ({' title ': ' WFC Test '}). ForEach (function(thisarticle) {Thisarticle.image_count=numberint (thisArticle.article_images.length) Db.test.articles.save (thisarticle)})//After you put the document's fields in a nested array, delete the field (data structure modification)db[' Test.game '].find ({' article_image ': {$exists: 0}}). ForEach (function(thisarticle) {articleimage= {' Remote ': Thisarticle.game_icon, ' local ': Thisarticle.game_local_icon,' Original ': Thisarticle.game_remote_icon, ' upload ': thisarticle.icon_upload} thisarticle.image_upload=thisarticle.icon_upload Thisarticle.modify_time=thisarticle.spider_time thisarticle.article_image=[] ThisArticle.article_image.push (articleimage)DeleteThisarticle.game_iconDeleteThisarticle.game_local_iconDeleteThisarticle.game_remote_iconDeletethisarticle.icon_upload db[' Test.game '].save (thisarticle)})//Group statistics by namedb[' Test.articles '].group ({key:{' Name ': 1}, condition:{' name ': {$exists: 1}}, $reduce:function(Curr, result) {Result.total+ = 1}, Initial:{total:0},})
Bulk Modify fields in MongoDB