Nodejs+express+mongoose Unable to obtain database data problem resolution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.