In a Document, if I have one to one relationship with a specific data set, there are two way we can define the collection:
- Option 1
{
_id: ObjectId("6159e58a11f8dcbed7883d56"),
CustomerID: 123456,
FirstName: 'John',
LastName: 'Smith',
MiddleName: 'Jr.',
UserType: 'Business',
address: [
{
addresstype: 'Primary',
address1: '33rd Street',
city: 'New York',
state: 'NY',
zipcode: '45875'
}
],
createduser: 'system',
createddate: ISODate("2021-10-03T17:16:58.748Z"),
updateduser: 'system',
updateddate: ISODate("2021-10-03T17:16:58.749Z")
}
- Option 2
{
_id: ObjectId("6159e5ae11f8dcbed7883d57"),
CustomerID: 123456,
FirstName: 'John',
LastName: 'Smith',
MiddleName: 'Jr.',
UserType: 'Business',
addresstype: 'Primary',
address1: '33rd Street',
city: 'New York',
state: 'NY',
zipcode: '45875',
createduser: 'system',
createddate: ISODate("2021-10-03T17:17:34.507Z"),
updateduser: 'system',
updateddate: ISODate("2021-10-03T17:17:34.507Z")
}
I understand how you define the model as its one to one is up to you as both ways work fine. The use case of sub document for address could be to make the data look cleaner and segregated in Option 1.
When it comes to using the address data in aggregation, you just need use doted notation in Option 1 to get your data elements.
So, my main Q is, if we have huge number of documents in this collection, does Option 1 with address has sub document has any downside in whatsoever fashion when it comes to Mongo DB internal working on how it stores the data and how easy is it to access the data?
Or, this has no bearing in any way and either way works exactly the same in all aspects?
Thanks