How to create a new db in mongoose?

17,943

It should not throw any error. The moment you insert a document in any new collection of that DB, the collection and db will be created

Share:
17,943

Related videos on Youtube

static
Author by

static

Updated on July 12, 2022

Comments

  • static
    static almost 2 years

    If I use Mongoose in node.js I need to do:

    var mongoose = require('mongoose');
    mongoose.connect('mongodb://localhost/myDB');
    

    But what if I just installed mongodb and I don't have any DB at the moment? How can I create a new DB using mongoose in node.js before doing mongoose.connect('mongodb://localhost/myDB')? Or if there is no such myDB then it will create a new one? or will throw an error that there is no such a DB?

    • static
      static almost 11 years
      do I see there an API createNewDB(...) ? no. How do I create a new DB using mongoose in node.js?
  • Luke H
    Luke H about 3 years
    This answer appears to be specific to express and also does not answer the question very well.