Home:ALL Converter>Single Collection vs Multiple collections with same fields in mongodb

Single Collection vs Multiple collections with same fields in mongodb

Ask Time:2018-10-18T20:52:57         Author:helloworld

Json Formatter

I have a collection in mongodb by the name Order. It has many fields some of which are mentioned below:

Order

{
    "id": "1",
    "name": "Hello1",
    "orderType": "Type1",
    "date": "2016-09-23T15:07:38.000Z"
     ...... //11 more fields
}

In the above collection, I have mentioned only 4 fields but in actual collection, I have around 15 fields. Order can be of 2 types: Type1 or Type2. It is mentioned in orderType field.

Now, for the Type2 order, I have all the 15 fields but it also have additional 5-7 fields. I have a single Order collection and I was wondering should I create 2 different collections for each type of orders; or whether I could keep this collection only and add additional fields here only. I have already written most of the logic considering only 1 collection Will it be worth the effort making it 2 different collections? If I keep a single collection, am I losing anything in terms of performance?

Author:helloworld,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52874511/single-collection-vs-multiple-collections-with-same-fields-in-mongodb
Rishabh Agarwal :

Keeping data on single collection is usually better in terms of performance since you can get required data mostly in a single query.\n\nSince from the question I can mostly think it is a one-to-one relationship, embedded documents would be beneficial. Secondly, you are yourself saying that you have already written most of the logic considering only one collection then you should go forward with one collection only. Unless you have one-to-many relationships.\n\nI would recommend you to go through Data Model Design and understand when and which model is better.",
2018-10-18T13:54:17
yy