1

I'm learning node and mongo and use mongoose for my modeling.

In the mongoose docs it says that mongoose.model, the first argument is singular name of the collection of your model. I find this hard to understand.

  1. My db name is CRMdb is this also the collection name?
  2. My model looks like this const Contact = mongoose.model('Contact', ContactSchema);, How does mongoose know automatically detect for the plural version of my model name? `
edmamerto
  • 7,605
  • 11
  • 42
  • 66
  • Possible duplicate of https://stackoverflow.com/questions/10547118/why-does-mongoose-always-add-an-s-to-the-end-of-my-collection-name – chridam Feb 07 '19 at 16:15

1 Answers1

2
  1. A collection is like a table, not a db, so no.
  2. You can also do it like this const Contact = mongoose.model('Contact', ContactSchema, 'contacts'); (in this case the collection name is contacts). Not really sure how they create the plural, but I don't really think it matters.
Haris Bouchlis
  • 2,366
  • 1
  • 20
  • 35