I'm trying to perform a single request to find the length of an array in a MongoDB document. In MongoDB, it can be done with an aggregation but to no success on my own.
db.mycollection.aggregate([{$project: { count: { $size:"$foo" }}}])
I've simplified the request (a lot) and think it can be optimized using the aggregate.
public int getArticlesCount(int id)
{
int test = collection.Find(x=>x.Id==id).First().articles.Count;
return test;
}
Is there any good way in the MongoDB C# to do this request?