node.js - node+mongoose beginner questions
某草草
某草草 2017-05-16 13:37:50
0
1
525
  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');
某草草
某草草

reply all(1)
左手右手慢动作

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template