Child objects in MongoDB

Posted by Jeremy B. on Stack Overflow See other posts from Stack Overflow or by Jeremy B.
Published on 2010-04-09T02:25:25Z Indexed on 2010/04/09 2:33 UTC
Read the original article Hit count: 547

Filed under:
|
|
|

I have been following along with Rob Conery's Linq for MongoDB and have come across a question. In the example he shows how you can easily nest a child object. For my current experiment I have the following structure.

class Content
{
    ...
    Profile Profile { get; set; }
}

class Profile
{
    ...
}

This works great when looking at content items. The dilemma I'm facing now is if I want to treat the Profile as an atomic object. As it stands, it appears as if I can not query the Profile object directly but that it comes packaged with Content results. If I want it to be inclusive, but also be able to query on just Profile I feel like my first instinct would be to make Profiles a top level object and then create a foreign key like structure under the Content class to tie the two together.

To me it feels like I'm falling back on RDBMS practices and that feels like I'm most likely going against the spirit of Mongo. How would you treat an object you need to act upon independently yet also want as a child object of another object?

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about LINQ