Add a new field to every document and give it the value of another field of the same document in mongodb -


this question has answer here:

i know how add field same value every document. want add "title_lower" field has same value "title" in lowercase.

{     "_id" : objectid("55a3907b8c5bf672f4ad319b"),     "title" : "oracle",     "title_lower" : "oracle",     "status" : "active",     "company_default" : true,     "is_deleted" : false  } 

i've come query add field cannot figure out second part:

db.getcollection('group').update(     {} ,     {$set : {"title_lower" : "title"}},     {multi:true}) 

will need write javascript file this?

the answer linked question worked me:

db.getcollection('group').find().foreach(   function(e) {     e.title_lower = e.title.tolowercase();     db.getcollection('group').save(e);   } ) 

Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -