1
使用Azure CosmosDB Mongo。WHERE子句Azure CosmosDB Mongo子文档
我在文档和子文档中有文本字段。我希望能够搜索。使用Contains
可以在父文档属性上正常工作。但似乎并不看孩子。甚至不会返回任何错误。
文件:
{
"TextField1": "this will be found in search",
"Comments": [{
"Comment": "amazing post, let's see if this can be foundtoo",
}, {
"Comment": "thanks",
}]
}
搜索:
var postFilter = Builders<MyObject>.Filter.Where(p => p.TextField1.ToLowerInvariant().Contains(searchText.ToLowerInvariant())) |
Builders<MyObject>.Filter.Where(p => p.Comments.Any(pc => pc.Comment.ToLowerInvariant().Contains(searchText.ToLowerInvariant())));
var posts = await Posts.Find(postFilter).ToListAsync();
如果我用搜索上面的代码 “发现”。它会返回文档。
如果我将它与搜索“foundtoo”一起使用。它不会返回任何东西。 PS:我已经尝试使用Text
,它不被支持,并作为错误返回。
感谢您的详细响应。会试试看。 – Yahya
你是明星! – Yahya