Wednesday, 15 September 2010

Error while using aggregation with limit property on mongodb in asp.net MVC4.0? -



Error while using aggregation with limit property on mongodb in asp.net MVC4.0? -

i utilize mongodb , mvc 4.0.

the below code gave me error, tried many different ways shows error:

"command 'aggregate' failed: exception: pipeline stage specification object must contain 1 field. (response: { "errmsg" : "exception: pipeline stage specification object must contain 1 field.", "code" : 16435, "ok" : 0.0 })"

my code:

var matchsumcount2 = new bsondocument { { "$group", new bsondocument { { "_id", new bsondocument { { "device","$device" } } }, { "clicks",new bsondocument { { "$sum","$clicks" } } }, { "day",new bsondocument { { "$sum",1 } } } } }, { "$limit",50 } }; var database = mongodbmanager.getdatabase(); var pipeline = new[] { matchsumcount2 }; var list = database.getcollection("rnd").aggregate(pipeline);

i want first 50 records , perform aggregation.

what doing wrong here? suggestion or code sample this?

i made comment above, didn't understand. apologize not beingness more clear. i'll utilize code examples show wrong.

you doing (effectively):

{ { $group: { _id: { device: "$device" } } }, { $limit: 50 } }

but wrong. $group , $limit should not siblings in document. should elements in array.

[ { $group: { _id: { device: "$device" } } }, { $limit: 50 } ]

like mentioned in comment, cannot see start of code, can create assumtpion based on end. first line new bsondocument(). wrong. should new bsonarray();

var pipeline = new bsonarray(); pipeline.add(new bsondocument( { { "$group", new bsondocument { { "_id", new bsondocument { { "device", "$device" } } } } } }); pipeline.add(new bsondocument("$limit", 50));

mongodb asp.net-mvc-4

No comments:

Post a Comment