If you want to use mongooes to connect to an existing data collection in the mongo database, you need to add a parameter {collection: "collection name"} when defining the schema. The collection name here is an existing collection in the database. As follows:
The definition of the model is the same as before:
The third parameter here is to solve the problem that the collection name in the database will automatically become plural
mongoose reads data from the database, no need for mongoose.collection('collectionName'). For complete learning, refer to the mongoose documentation. A simple example is as follows, where {} is specific conditions or data. -- model.js --
If you want to use mongooes to connect to an existing data collection in the mongo database, you need to add a parameter {collection: "collection name"} when defining the schema. The collection name here is an existing collection in the database. As follows:
The definition of the model is the same as before:
The third parameter here is to solve the problem that the collection name in the database will automatically become plural
mongoose reads data from the database, no need for mongoose.collection('collectionName').
For complete learning, refer to the mongoose documentation. A simple example is as follows, where {} is specific conditions or data.
-- model.js --
-- CRUD data --
soonfy
Please refer to the relevant chapters of Mongoose’s documentation:
http://mongoosejs.com/docs/qu...
For reference.
Love MongoDB! Have Fun!