Search code examples
node.jsmongodbsails.jssails-mongo

How do I rename all the fields in my database schema using Sails.js, sails-mong and Mongo DB


I have a sails app using sails-mongo and mongo db ... in the Database schema I originally named on of the fields 'name', I've since named the same key in other data types 'deviceName'. I would like to rename all of the records so that the field is updated to deviceName but I'm struggling with the best way to go about doing that. I saw an NPM module called migrate ... seem like in might be promising


Solution

  • You can use the $rename operator in mongodb. Here is the mongodb docs for rename

    Update
    There are already a great SO post regarding this. Check out this thread.