Single Collection Vs Multiple Collection for Reporting

Hi Team,

We are working on a project. We need your suggestion on defining our schema for the report collection. We have 5 types of reports. Now we are thinking to keep one collection for them instead of 5 collections. Is it a good idea to keep them in a single collection or it’s better to keep them in a different collection? We are finding an alternative as we don’t want to run into performance issues.

1 Collection with all types of Reports

{
        Type: Job1 ('Job1', Print, Scan, AddValue, Fine),
        TransactionDate: String,
        TransactionStartTime: String,
        TransactionEndTime: String,
        TimeZone: String,
        BarcodeNumber: String,
        FullName: String,
        EmailAddress: String,
        Balance: Balance
        Job1: {
          10 more fields
        }
}

{
        Type: Print ('Job1', Print, Scan, AddValue, Fine),
        TransactionDate: String,
        TransactionStartTime: String,
        TransactionEndTime: String,
        TimeZone: String,
        BarcodeNumber: String,
        FullName: String,
        EmailAddress: String,
        Balance: Balance
        Print: {
          10 more fields
        }
}

Separate these collections into 5

{
        Type: Job1,
        TransactionDate: String,
        TransactionStartTime: String,
        TransactionEndTime: String,
        TimeZone: String,
        BarcodeNumber: String,
        FullName: String,
        EmailAddress: String,
        Balance: Balance
        Job1Field1: value,
        Job1Field2: value,
        Job1Field3: value
        so on...
}

{
        Type: Print,
        TransactionDate: String,
        TransactionStartTime: String,
        TransactionEndTime: String,
        TimeZone: String,
        BarcodeNumber: String,
        FullName: String,
        EmailAddress: String,
        Balance: Balance
        PrintField1: value,
        PrintField2: value,
        Printield3: value,
        and so on...
}

Hi @Tudip_Company ,

Welcome to MongoDB community.

Since MongoDB have a flexible schema it make sense to hold similar documents in the same collection.

In this case since lots of fields are same cross job types:


{
Type: Job1 (‘Job1’, Print, Scan, AddValue, Fine),
TransactionDate: String,
TransactionStartTime: String,
TransactionEndTime: String,
TimeZone: String,
BarcodeNumber: String,
FullName: String,
EmailAddress: String,
Balance: Balance
JobDetails: {
10 more fields
}
}

The question on how to index this dataor restructure further is dependent on the Access patterns…

Thanks
Pavel

Thanks, Pavel for the response. Will it affect the performance for querying larger data.

Not sure I understand the question?