search

Home  >  Q&A  >  body text

node.js - node+mongoose beginner questions

  1. Does database creation have to be performed in mongodb? Can a database be created in mongoose?

  2. Does the data type of each field (key?) have a length range?

  3. mongoose.model() and db.model() are both modeling, but what is the difference?

    let mongoose = require('mongoose'),
        db = mongoose.connect('mongodb://localhost:27017/test');
某草草某草草2801 days ago544

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 13:39:50

    Let me know in advance. I am also a newbie. The following is for reference only. If there are any errors, please point them out

    1. Database creation requires mongodb, and collection creation can be completed in mongoose

    2. There will definitely be a limit to the length, but it will not affect normal use. You don’t need to consider this at ordinary times

    3. If there are multiple databases, use
    mongoose.createConnection, which will return the connection object, and then you can operate on different databases respectively. If it is a single database, just use mongoose.connect

    Oh, yes, the db=mongoose.connect.... you wrote last is a mistake. This method does not return the database

    Therefore, mongoose.model is equivalent to modeling a single database, and dbName.model is equivalent to modeling different dbNames

    reply
    0
  • Cancelreply