mongodb - use db.update to update all the documents -


I want to use a Mongo Shell to update some documents that looks like this: < ("54265f801681140a66ca45de"), "Username": "000000002-xqsh", "Name": "xxxxx", "__v": 0}

I want to change the dash - to enter _ to enter usernames . Can I make it a Mongo shell? My Mongo shell version is as follows:

  & gt; Version () 2.6.4    

  db.c.find (user name : / - /}, {user name: 1}) .for (function (e) {var user name = e.username.replace ("-", "_"); db.c.update ({_ id : E._id}, {$ set: {username: username}})}}   

If you want to change to all user names,

 Use the  db.c.find ({user name: / - /}, {username}: 1}). Pre (function (e) {var username name = e.username.replace (/ - / g , "_"); Db.c.update ({_ id: e._id}, {$ set: {username: users Class Name}});});    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -