MongoDB C# 2.4.4 Filter documents where all elements of a string array are in another array -
i'm working le latest c# mongodb driver (2.4.4). cannot find way filter collection elements of string array property in array (as input parameter).
data : ["a", "b"] - input : ["a", "c", "b"] => ok
data : ["a", "b"] - input : ["a", "c"] => ko
here ligh version of model. have collection of shipments, each shipment has string array of functions , subdocument array of shippingdocuments. each shippingdocument has string array of functions.
shipment[] reference functions[] shippingdocument[] functions[] i have string array of functions in input paramaters (myfunctions). want achieve mongo shell command c# api aggregation pipeline.
{$match:{"functions":{$in:myfunctions,$not: {"$elemmatch":{"$nin":myfunctions}}}}} => if find single element not in input array it's ko.
i need same thing shippingdocument array fine $project.
var db = client.getdatabase("ecom"); var collection = db.getcollection<shipment>("shipment"); var query = collection.aggregate() .match( builders<shipment>.filter.eq(x => x.reference, "xxx") & (/*{$match:{"functions":{$in:myfunctions,$not: {"$elemmatch":{"$nin":myfunctions}}}}}*/) ) .project(s => new { reference = s.reference, documents = s.shippingdocuments.where(d => d.functions.all(ro => myfunctions.contains(ro))) } ); if try add match,
builders<shipment>.filter.where(x => x.functions.all(f => myfunctions.contains(f))) i have exception,
unsupported filter: all({document}{functions}.where(contains(value(system.collections.generic.list`1[system.string])))). any ideas achieve ?
Comments
Post a Comment