0

Here I want to drop my collection(Table in MySQL) but I can't understand why we add 's' to the name of the collection, sample:
[name of Collection(table) : myCollection]

const mongoose = require('mongoose');
 mongoose.connection.collections.myCollections.drop();
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Yasin Hajilou
  • 247
  • 3
  • 11
  • Please actually search for answers before posting here. Your question title is almost exactly the same as the existing answer. It's easy for me to find and easy for others to find. Things like this are so easy to find that in fact most answers you would attract from such questions will merely copy from the easy to find answer. That's why we ask you to search first, because we don't want that. – Neil Lunn Apr 27 '18 at 22:06

1 Answers1

0

A model is representative of one singular item. A collection is a bunch of those singular items. Mongoose does some auto pluralization so you will have to dig into the docs into how to customize it or adjust it.

According to their docs Mongoose by default produces a collection name by passing the model name to the utils.toCollectionName method. This method pluralizes the name. Set this option if you need a different name for your collection.

Check out http://mongoosejs.com/docs/guide.html for more info

HarryH
  • 1,058
  • 7
  • 12