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:
- update mongodb collection using $tolower 4 answers
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
Post a Comment