1

Let's say I have a mongoDB database with 3 collections:

  • widgets
  • thingomajiggers
  • locations

The way the application is going to be used that I will always force the user to specify a location first. and then from there, they can drill down into the type object they are looking to read / create / update - namely either a widget or a thingomajigger.

So in this case, would it be better to have a separate location collection and refer to this collection from the documents in widgets and thingomajiggers, or should I embed location information right inside my widget / thingomajigger documents?

Currently my prototype is small so I can't imagine me really noticing performance differences. But eventually I will have hundreds of thousands of widgets and other object types.

Thanks.

3

I think I found my answer from the mongoDB manual:

In general, use embedded data models when:

  • you have “contains” relationships between entities. See Model One-to-One Relationships with Embedded Documents.
  • you have one-to-many relationships between entities. In these relationships the “many” or child documents always appear with or are viewed in the context of the “one” or parent documents. See Model One-to-Many Relationships with Embedded Documents.

http://docs.mongodb.org/manual/core/data-model-design/

The later scenario would apply to me.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.