views:

176

answers:

2

I saw this Q&A http://stackoverflow.com/questions/2900763/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 (http://wiki.github.com/atheken/NoRM/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!

+1  A: 

You can certainly do this, just GetCollection("collectionName") or GetCollection("collectionName") and you can do all the standard operations. The downside of using Expando is that you don't get intellisense or LINQ, but in your case, that is ok.

Andrew Theken
+1  A: 

Hi

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").

Cheers

Ramesh Vel