如何在ASP.NET上使用MongoDB搜索索引 /索引
当我使用一个简单的发现检索所有数据时,我收集了10 000个文档,(〜6 MB),
它需要一分钟以上的时间才能检索所有文档。
我在MongoDB上创建了一个搜索索引,以加快我想实现的目标。
我也有一个搜索索引:
这是此搜索索引的查询语法:
new BsonArray {
new BsonDocument("$search", new BsonDocument {
{
"index",
"searchProd"
},
{
"text",
new BsonDocument {
{
"query",
application // DYNAMIC Value that I want to pass
},
{
"path",
new BsonDocument("wildcard", "*")
}
}
}
})
}
找不到如何在我的函数上实现它的方法。
public async Task<List<Produit>> ListAllProducts(string application)
{
var sw = Stopwatch.StartNew();
var allProducts = await _produits.Find(new BsonDocument("$search", new BsonDocument
{
{
"index",
"searchProd"
},
{
"text",
new BsonDocument
{
{
"query",
application
},
{
"path",
new BsonDocument("wildcard", "*")
}
}
}
})).ToList();
return allProducts;
}
通过这样做,我得到了
mongodb.driver.mongocommandexception:命令查找失败:未知顶部 电平操作员:$搜索。如果您的字段名称以一个开始 '$'符号,考虑使用$ getfield或$ setfield ..
谢谢。
I have a collection of 10 000 documents, (~ 6 Mb)
When I'm using a simple find to retrieve all the data, it takes like more than a minute to retrieve all the documents.
I created a search Index on MongoDb to speed up what I want to achieve.
I have also a search Index :
Here is the Query Syntax of this Search Index :
new BsonArray {
new BsonDocument("$search", new BsonDocument {
{
"index",
"searchProd"
},
{
"text",
new BsonDocument {
{
"query",
application // DYNAMIC Value that I want to pass
},
{
"path",
new BsonDocument("wildcard", "*")
}
}
}
})
}
Couldn't find a way how to implement this on my function.
public async Task<List<Produit>> ListAllProducts(string application)
{
var sw = Stopwatch.StartNew();
var allProducts = await _produits.Find(new BsonDocument("$search", new BsonDocument
{
{
"index",
"searchProd"
},
{
"text",
new BsonDocument
{
{
"query",
application
},
{
"path",
new BsonDocument("wildcard", "*")
}
}
}
})).ToList();
return allProducts;
}
By doing this I'm getting
MongoDB.Driver.MongoCommandException: Command find failed: unknown top
level operator: $search. If you have a field name that starts with a
'$' symbol, consider using $getField or $setField..
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Atlas
$ search
是一个聚合阶段,而不是查找
参数。它应该看起来与:atlas
$search
is an aggregation stage, notfind
argument. It should look similar to: