2

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

If I use this command:

db.getCollection('requests').find({"claims.id": 1002})

It is not working in cosmosdb mongo api but working for local mongo service instance I have hosted.

my request object is as below

{
    "_id" : NumberLong(1001),
    "claims" : [ {
            "type" : "broadband",
            "id" : NumberLong(1002),
            "createdOn" : NumberLong(1462799667905)
              } ]
}
1
  • Your code seems mess (as in format), please see how you can enhance its look. Commented Jun 16, 2017 at 10:58

1 Answer 1

2

Not all of MongoDB's query syntax / capabilities are implemented. This appears to be such a case.

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")
    }
  ]
}

Note that you can also call db.request.find() without the need for a call to getCollection().

Sign up to request clarification or add additional context in comments.

2 Comments

David, can you please show the workaround how to update the object inside an array ?
Would be nice to know which if any are implemented :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.