C # Mongo Driver - MongoCollection.Group method

I tried to dig around the Internet everywhere, but I can’t find life for me how to use this method. I tried to look at the mongo console to correlate the two, but mine he defeated my brain. Can someone help me with this at all or point me to the side of help?

I am using the C # driver from mongodb.org.

I have the following document:

ObjectId ForeignId

I would like to count the number of documents and group the account by the ForeignId field. Thank!

+3
source share
2 answers

It looks slightly off (parameter order). It should be:

var document = new BsonDocument("count", 0);
var result = myCollection.Group<BsonDocument>(
    Query.Null,
    "ForeignId",
    document,
    new BsonJavaScript("function(doc, out){ out.count++; }"),
    null
);

There is a similar example in TestGroup unit test in MongoCollectionTests.cs.

+4
source

I THINK I answered my question through hacking:

var document = new BsonDocument("count", 0);
myCollection.Group<BsonDocument>(
    "ForeignId",
    null,
    document,
    new BsonJavaScript("function(doc, out){ out.count++; }"),
    null
);
0
source

Source: https://habr.com/ru/post/1788749/


All Articles