Why does Mongoose automatically add S and lowercase when creating a collection?

  mongodb, question

I didn’t find any explanation in the document, please give me some advice, thank you.

Mongoose creates the corresponding collection in mongoose DB through model. Mongoose lowercase the collection name (‘Friend Expression’) we pass when creating the collection internally. At the same time, if the lowercase name is not followed by the letter-S, it will be followed by an S. For the collection we just built, it will be named: friendimpressions.

1. Find from the document:

The first argument is the singular name of the collection your model is for. Mongoose automatically looks for the plural version of your model name. Th us, for the example above, the model Tank is for the tanks collection in the database. The .model() function makes a copy of schema. Make sure that you’ve added everything you want to schema before calling .model()!

2. You can specify the name of the collection in the third parameter.

For reference!

Love MongoDB! Have fun!


The 2017MongoDB Chinese Community Beijing User Group Conference is approaching, June 3, 2017, 13: 00-18: 00

Sign up!Please poke left!