c# - Grouping mongodb filtered results by reference id throws -
i have simplified model:
public class parent { public objectid id { get; set; } } public class child { public objectid id { get; set; } public objectid parentid { get; set; } [bsonrepresentation(bsontype.string)] public gender gender { get; set; } }
i have queried parents filter on fields i've intentionally omitted. have parent id collection. want children gender.male
parents had obtained first query , group them can have mapping between parent
, list<child>
.
var parentids = filteredparents.select(p => p.id).tolist(); var childrenfilter = builders<child>.filter.in(c => c.parentid, parentids) & builders<child>.filter.eq(c => c.gender, gender.male); var aggregation = children .aggregate() .match(childrenfilter) .group(c => c.parentid, g => new keyvaluepair<string, list<child>>(g.key, new list<child>(g))); var groupcursor = await aggregation.tocursorasync();
this throws
system.notsupportedexception: not find member match constructor parameter collection on type list`1.
a few small side questions
i assume i've written
childrenfilter
in such way executed on server , client won't receivegender.female
children? if that's not true - proper way it? , if used overloadlinq.expression
- filter executed on server or on client?are children grouped on server or on client? how should write
group
in order executed on server should more efficient?
update 17.06
as per @craigwilson's suggestion tried g.tolist()
:
var aggregation = children .aggregate() .match(childrenfilter) .group(c => c.parentid, g => new keyvaluepair<string, list<child>>(g.key, g.tolist()));
which led different exception:
unhandled exception: system.aggregateexception: 1 or more errors occurred. --- system.invalidcastexception: unable cast object of type 'mongodb.driver.linq.expressions.serializationexpression' type 'system.linq.expressions.methodcallexpression'.
Comments
Post a Comment