【问题标题】:CosmosDB mongoDB API sort and full text search throwing errorCosmosDB mongoDB API 排序和全文搜索抛出错误
【发布时间】:2021-09-25 19:45:45
【问题描述】:

我正在使用 CosmosDB MongoDB API 来存储和检索集合中的文档。

我正在尝试使用排序 collection.find({}).sort({field1: 1} 并看到此错误:

"message": "Failed to retrieve the document:MongoError: Error=2, Details='Response status code does not indicate success: 
BadRequest (400); Substatus: 0; ActivityId: d05b7772-3252-4005-898f-4480cadfb8e1; Reason: 
(Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 
d05b7772-3252-4005-898f-4480cadfb8e1; Reason: (Response status code does not indicate success: BadRequest (400); 
Substatus: 0; ActivityId: d05b7772-3252-4005-898f-4480cadfb8e1; Reason: (Message: {\"Errors\":
[\"The index path corresponding to the specified order-by item is excluded.\"]}\r\nActivityId: d05b7772-3252-4005-898f-4480cadfb8e1, 
Request URI: /apps/e118124c-80f3-408e-a2f9-fbea51664ad4/services/5cb63213-f046-49d6-9825-0bfa4010772e/partitions
/68271031-2d85-44cd-9929-8857ff69b63e/replicas/132696733163313635s/, 
RequestStats: Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, 
SDK: Windows/10.0.17763 cosmos-netstandard-sdk/3.18.0);););"

是不是说没有索引就不能在MongoDB上做排序?

想知道这是 MongoDB 行为还是 CosmosDB 行为?不确定。

第二个问题是:我想对所有字段进行字符串搜索,如下所示:

 collection.find({"$text":{"$search":"findMeOut"}});

但是在这里我看到了这个 Mongo 错误:

MongoError: $text not supported

现在这意味着什么?

我正在使用 CosmosDB MongoDB API,使用 JavaScript 和 NodeJs 本机 MongoClient,版本如下:

 "mongodb": "^3.6.10",
 "fastify-mongodb": "^2.0.1",

谢谢。

【问题讨论】:

  • 这个问题的解决方法是什么?

标签: mongodb-query azure-cosmosdb-mongoapi


【解决方案1】:

分享你的模型真的很有帮助。 AFAIK,为了使用文本搜索,您必须使用索引名称 text 对要执行搜索的字段进行索引。你可以看看this issue,我相信这与你的问题相似

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-16
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 2021-04-07
    • 2016-01-15
    相关资源
    最近更新 更多