Operate with MongoDB via Mongoose. The mongoose is created by the model to create the corresponding collection in MongoDB, so that you pass the following code:
mongoose.model(‘User‘, UserSchema);
When creating a collection in the corresponding database, the first reaction will certainly infer that a ' User ' collection, but the fact is completely different from inference, mongoose the collection name we passed when creating collection internally, and if there is no letter--s after the lowercase name, a s is added after it. For the collection we just built, it will be named: Users.
You can change the name of collection in the following two ways:
In the schema:
1.xxschema = new Schema ({...}, {collection: "Your Collection Name"});
In model:
2.mongoose.model (' User ', Userschema, ' your collection name ');
Original address: Https://cnodejs.org/topic/4f71363f8a04d82a3d1e4aea
Nodejs+express+mongoose Unable to obtain database data problem resolution