我需要获取所有由用户列表创建的井。以下是我为此要求编写的代码。但是x.CreatedBy.ToLower()引发下面列出的异常:
FilterDefinition<WellInfoDocument> userFilter = builder.Where(x => users.Contains(x.CreatedBy.ToLower()));
var documentList = await GetCollection<WellInfoDocument>().FindAsync<WellInfoDocument>(userFilter);```
System.ArgumentException: Unsupported filter: Contains(value(System.Collections.Generic.List`1[System.String])).
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.MongoCollectionImpl`1.CreateFindOperation[TProjection](FilterDefinition`1 filter, FindOptions`2 options)
at MongoDB.Driver.MongoCollectionImpl`1.FindAsync[TProjection](IClientSessionHandle session, FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.<>c__DisplayClass43_0`1.<FindAsync>b__0(IClientSessionHandle session)
at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
Any suggestions to fix is welcome. TIA
给$in过滤器去。
var filter = Builders<WellInfoDocument>.Filter.In(x => x.CreatedBy.ToLower(),users.Select(x => x.Id).ToList());
var documentList = await GetCollection<WellInfoDocument>().FindAsync<WellInfoDocument>(filter);
不确定您的类型或外观,但是您应该可以从此示例中得出结论。