Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongoose rename collection

const mongoose   = require('mongoose');
mongoose.Promise = Promise;

mongoose.connect('mongodb://localhost/test').then(() => {
  console.log('connected');

  // Access the underlying database object provided by the MongoDB driver.
  let db = mongoose.connection.db;

  // Rename the `test` collection to `foobar`
  return db.collection('test').rename('foobar');
}).then(() => {
  console.log('rename successful');
}).catch(e => {
  console.log('rename failed:', e.message);
}).then(() => {
  console.log('disconnecting');
  mongoose.disconnect();
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mongoose #rename #collection
ADD COMMENT
Topic
Name
2+7 =