【发布时间】:2021-04-15 12:53:58
【问题描述】:
我有一个 IMongoCollection 内容:
collection = [
{Value = 'x', EntryPoint= 'ROOT/1' },
{Value = 'y', EntryPoint= 'ROOT/2' },
{Value = 'z', EntryPoint= 'OTHER/1' }]
现在我想过滤我的收藏
userEntryPoints = ['ROOT', 'SPECIAL'].
我们定义了,如果我有entrypoint = 'ROOT',那么我们也有'ROOT/1', 'ROOT2'的入口点。
所以预期的结果是
result = [
{Value = 'x', EntryPoint= 'ROOT/1' },
{Value = 'y', EntryPoint= 'ROOT/2' }]
我使用的代码是
var collection = mongoDatabase.GetCollection(Data);
return collection.AsQueryable().Select(xxx)
.Where(item => userEntryPoints.Any( entrypoint => item.EntryPoint.StartsWith(entrypoint)))
如果 collection 和 userEntryPoints 是简单数组,这应该可以工作。
但在我的代码中,在运行时我有一个 mongodb 错误:
Unsupported filter: Any(value(System.Collections.Generic.List`1[System.String]].Where({document}{EntryPoint}.StarsWith(document))))
At MongoDB.Driver.Linq.Traslators.PredicateTranslator.Translate(Expression node)
我可以做些什么来使这种过滤成为可能? 谢谢。
【问题讨论】: