Does database creation have to be performed in mongodb? Can a database be created in mongoose?
Does the data type of each field (key?) have a length range?
mongoose.model()
and db.model()
are both modeling, but what is the difference?
let mongoose = require('mongoose'),
db = mongoose.connect('mongodb://localhost:27017/test');
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.connectOh, 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