AllowDiskUse in aggregation structure with MongoDB C # driver

I would like to enable DiskUse: true. However, I could not find a single example explaining allowDiskUse, which allows you to use the MongoDB C # driver.

How to enable enableDiskUse in C # MongoDB driver?

My sample code like this

    var pipeline = new[] { match, project, group, limit, sort, allow };

    List<SMBMostInfluentialUser> result = db
        .GetCollection<SMBTwitterStatus>("TwitterStatus")
        .Aggregate(pipeline).ResultDocuments.Select(x =>
            new User
        {
            Influence = Convert.ToDouble(x["Influence"]),
            User = new SMBUser((BsonDocument)x["User"])
        }).ToList();
+4
source share
2 answers

Use another Aggregate overload, which takes an AggregateArgs parameter and gives you more control over the operation, including setting AllowDiskUse:

var pipeline = new BsonDocument[0]; // replace with a real pipeline
var aggregateArgs = new AggregateArgs { AllowDiskUse = true, Pipeline = pipeline };
var aggregateResult = collection.Aggregate(aggregateArgs);
var users = aggregateResult.Select(x =>
    new User
    {
        Influence = x["Influence"].ToDouble(),
        User = new SMBUser(x["user"].AsBsonDocument)
    }).ToList();

Note that the return type of this Aggregate overload is IEnumerable <BsonDocument> so you no longer need to use the ResultDocuments property.

, , Select . , , , , .

+4

MongoDB # ( , ), :

var aggregateOptions = new AggregateOptions{ AllowDiskUse = true};
var aggregateResult = collection.Aggregate(aggregateOptions);
0

All Articles