mongodb-query - CosmosDB mongoDB API 排序和全文搜索抛出错误
问题描述
我正在使用 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",
谢谢。
解决方案
分享你的模型真的很有帮助。AFAIK,为了使用文本搜索,您必须使用索引名称text对要执行搜索的字段进行索引。你可以看看这个问题,我相信它与你的问题相似
推荐阅读
- graphql - 在 GRAPHQL 上创建评论时将阶段添加到 PUBLISHED
- react-native - 单击一个反应本机后,禁用所有按钮一段时间
- python - 如何将熊猫数据框传递给气流任务
- java - 特征不能写多于一次
- mysql - 计算具有多列的表中的所有出现次数 (SQL)
- python - CCXT Exchange 作为函数中的本地变量和类中的属性
- flutter - DateTime.add() 没有有效地添加请求的时间量
- android - Kotlin 等待函数完成然后完成代码
- java - while false 循环的大符号是什么?
- python - 如何在视图中获取 JSON 字段以进行序列化