MongoDB C# driver query operators in QueryDocument or $not $size alternative
I couldn't quite find something like this, hence the question. I have a page\blarg collection that has an array of Categories. I'd like to be able to pull a list of existing categories and I don't want to do a Map Reduce so I decided I would just pull all of the categories and then filter them for uniqueness client side. I'd like to only pull arrays that are not empty, though, so I devised the following query:
{ Categories : { $not { $size : 0 } } }
However I don't know how to replicate it using the driver. $Not takes a BsonValue 开发者_如何转开发and $Size just takes an int, I'm not sure how to put a $Size condition in the $Not query. I figured I could use a QueryDocument or something but i'm not sure how to emulate operators via anonymous objects (or at least I haven't seen any documentation on it).
P.S. I realize I might be able to do an Query.EQ("Categories", BsonArray.Create(new List())) or something but I'm interested in the answer for the principle of it at this point, I can think of another scenario where I might want any arrays in which there is more or less than one entry for instance.
You can express your query in C# as follows:
var query = Query.Not("Categories").Size(0);
You can verify that it is in fact the same query with:
var json = query.ToJson();
精彩评论