我有一个使用 spring-data mongo API 从 Cosmos Db 获取数据的 spring 应用程序。使用 mongo 模板运行特定的查找聚合时,我遇到了以下InvalidDataAccessApiUsageException异常:
Command failed with error 115 (CommandNotSupported): 'Unique and compound indexes do not support nested paths.' on server localhost:10255. The full response is {
"ok": 0.0,
"errmsg": "Unique and compound indexes do not support nested paths.",
"code": 115,
"codeName": "CommandNotSupported"
}
据我了解,每个Azure 文档 CommandNotSupported是 Cosmos Mongo API 不完全支持的功能。但是,此错误仅在第一次执行查找聚合时发生,所有后续执行都按预期工作,没有错误。每次我们重新启动应用程序时,此问题都会重复出现。
这是重新创建此异常的伪代码设置。考虑 2 类模型“产品”和“配件”我想使用查找聚合合并到商品类中:
@Document(collection = "products")
@CompoundIndexes({@CompoundIndex(
name = "fieldA_fieldB_fieldC_fieldD",
def = "{'fieldA': 1, 'fieldB' : 1, 'fieldC': 1,'fieldD' : 1}"
)})
class Products {
//...
}
@Document(collection = "accessories")
@CompoundIndexes({@CompoundIndex(
name = "fieldA_fieldB_fieldC_fieldD",
def = "{'fieldA': 1, 'fieldB' : 1, 'fieldC': 1,'fieldD' : 1}"
)})
class Accessories {
//...
}
// Aggregate Model
class Merchandise extends Products {
List<Accessories> accessoriesList;
}
// Lookup Aggregate
mongoTemplate.aggregate(
Aggregation.lookup(
"accessories",
"localKey",
"foreignKey",
"new_column_name"),
"products", Merchandise.class);
我已经测试过:
- CosmosDb 模拟器(api v3.6)-> 相同的行为,错误 115
- Azure 上的 CosmosDb (api v3.6) -> 行为相同,错误 115
- MongoDb v3.6 docker 容器 -> 好的,没有错误
作为一种解决方法,我创建了没有要扩展的 mongo 特定注释的基本模型类。这可以按预期工作,没有问题:
@Document(collection = "products")
@CompoundIndexes({@CompoundIndex(
name = "fieldA_fieldB_fieldC_fieldD",
def = "{'fieldA': 1, 'fieldB' : 1, 'fieldC': 1,'fieldD' : 1}"
)})
class Products extends ProductsBase{
}
@Document(collection = "accessories")
@CompoundIndexes({@CompoundIndex(
name = "fieldA_fieldB_fieldC_fieldD",
def = "{'fieldA': 1, 'fieldB' : 1, 'fieldC': 1,'fieldD' : 1}"
)})
class Accessories extends AccessoriesBase {
}
// Aggregate Model using *Base classes instead.
class Merchandise extends ProductsBase {
List<AccessoriesBase> accessoriesList;
}
我的问题是,如果发出的错误指定该命令不受支持,为什么此查找聚合第一次不起作用,但随后所有时间都起作用?或者这是与如何设置索引有关的问题?