I am trying to get some random items from a database using the Sample () method . I updated to the latest driver and copied using statements from a related example. However, something is not working, and I hope this will be some simple mistake on my part. All relevant information is in the image below:

Edit:
Greg, I read aggregated documents here and the raw db doc method here , but I still don't get it. The last two lines are my attempts, I have never used aggregation before:
var mongoCollection = GetMongoCollection<BsonDocument>(collectionName);
long[] locationIds = new long[] { 1, 2, 3, 4, 5 };
var locationsArray = new BsonArray();
foreach (long l in locationIds) { locationsArray.Add(l); };
FilterDefinition<BsonDocument> sampleFilter = Builders<BsonDocument>.Filter.In("LocationId", locationsArray);
var findSomething = mongoCollection.Find(sampleFilter);
var aggregateSomething = mongoCollection.Aggregate(sampleFilter).Sample(25);
var aggregateSomething2 = mongoCollection.Aggregate().Match(sampleFilter).Sample(25);
source
share