I have a members collection in MongoDB database where each document looks like this:

    "_id" : "8801",
    "name" : "John Doe"

I need to store family relationships between members. That relationship is not directed.

Let's say John and Martha and Peter are family. When I query for John's family, I want Martha and Peter to be returned.

What is the best design for this? I have been thinking in a families collection where each document looks like:

    "_id" : "01",
    "members": ["8801", "0121", "7767"]

And query using $in operator against the families.members field.

What do you think? Am I losing NoSQL power when using this approach? Is there a better way?

Your Answer

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

Browse other questions tagged or ask your own question.