Search code examples
c#mongodbdynamicexpandonosql

MongoDB NoRM: query nested objects using Expando


I saw this Q&A MongoDB Norm query nested objects, but it seems to apply to strongly-typed objects only.

Is there a way to do a find or update a nested field on an Expando object (https://github.com/atheken/NoRM/wiki/expando)? Basically, I have a simple JSON CMS tool that lets developers store document objects on the server, which would then be serviced to Flash clients. I would need provide a simple service where a developer can create a JSON object, save it, make nested queries and also update these objects.

Since, the data structure is not known, I thought this would be a perfect place to use MongoDB. Unfortunately, .Net seems better suited for strongly-typed data structures.

Any ideas? Thank you!


Solution

  • As Andrew said you dont get intelligence support for expando objects since the document type is unknown at compile time. Instead you can query it like this

                var query = new Expando();
                query["comments.Author"] = Q.Equals("R");
                Mongo mongo = new Mongo(connection);
                var reer = mongo.GetCollection<Expando>("Blog").Find(query).ToList();
    

    Explanation:

    This retrieves the all the Blog documents by querying the embedded document comments (comments.Author="R").