Unable to retrieve documents in Cosmos DB stored procedure


Author: ramakumarja

Originally Sourced from: https://stackoverflow.com/questions/63955597/unable-to-retrieve-documents-in-cosmos-db-stored-procedure

I'm trying to retrieve documents matching an id through a simple SQL query in my JavaScript stored procedure. But it always returns that no document matches the id found. Tried all the things available in the Microsoft Documentation and the other StackOverflow answers. Here is my function:

function updateDocument () {
  let context = getContext();
  let collection = context.getCollection();
  let collectionLink = collection.getSelfLink();
  let response = context.getResponse();

  tryQueryAndUpdate();

  function tryQueryAndUpdate () {
    var filterQuery = 'select * from user r WHERE r.id = "f5eddf33-7826-40c3-a634-9c349e5c7f73"';

    let isAccepted = collection.queryDocuments(collectionLink, filterQuery, {}, function (err, documents, responseOptions) {
      if (err) throw err;

      if (documents.length > 0) {
        console.log("Documents exists - " + documents.length);
      } else {
        // Else a document with the given id does not exist..
        console.log("Document doesn't exist " + documents.length);
      }
    });
  }
}

My document:

{
    "firstName": "firstname",
    "lastName": "lastname",
    "email": "firstname.lastname@gmail.com",
    "businessRole": "",
    "functionalArea": null,
    "type": "internal",
    "status": "enable",
    "modifiedDate": "2020-07-10T14:34:54.557Z",
    "id": "f5eddf33-7826-40c3-a634-9c349e5c7f73",
    "_rid": "H+pKAKZdGd0BAAAAAAAAAA==",
    "_self": "dbs/H+pKAA==/colls/H+pKAKZdGd0=/docs/H+pKAKZdGd0BAAAAAAAAAA==/",
    "_etag": "\"730103dd-0000-0100-0000-5f6302800000\"",
    "_attachments": "attachments/",
    "securityGroup": "c5d3dc10-bfa0-11ea-8394-48463089baf6",
    "engagementId": "945acacf-a3ea-43ef-8e31-70576055ba4f",
    "sort": {
        "firstName": "firstname",
        "lastName": "lastname"
    },
    "userStatus": "active",
    "_ts": 1600324224
}

document: container:

Any help would be appreciated. Thank you.

Execution parameters:

Execution parameters

Console output:

Console output