我正在使用Azure上的 cosmosdb 因为我正在使用 mongodb api 我有一个请求" 集合,里面有一个声明" 数组
I am using cosmosdb on azure In that I am using mongodb api I have a "request" collection inside that there is a "claims" array
如果我使用此命令:
db.getCollection('requests').find({"claims.id": 1002})它不适用于cosmosdb mongo api,但适用于我托管的本地mongo服务实例.
It is not working in cosmosdb mongo api but working for local mongo service instance I have hosted.
我的请求对象如下
{ "_id" : NumberLong(1001), "claims" : [ { "type" : "broadband", "id" : NumberLong(1002), "createdOn" : NumberLong(1462799667905) } ] }推荐答案
并非所有MongoDB的查询语法/功能都已实现.似乎是这种情况.
Not all of MongoDB's query syntax / capabilities are implemented. This appears to be such a case.
但是,这种轻微的解决方法应该对您有用-我刚刚在自己的CosmosDB(MongoDB API)集合中对其进行了测试:
However, this slight workaround should work for you - I just tested it on my own CosmosDB (MongoDB API) collection:
db.getCollection('request').find({claims: { $elemMatch: { id:1002 }}}).pretty() { "_id" : 1001, "claims" : [ { "type" : "broadband", "id" : 1002, "createdOn" : NumberLong("1462799667905") } ] }请注意,您也可以呼叫db.request.find()而不需要呼叫getCollection().
Note that you can also call db.request.find() without the need for a call to getCollection().
更多推荐
cosmosdb mongo api对于某些命令不起作用
发布评论