0
votes

I've been observing some strange behaviour in a stored procedure in Azure Cosmos DB using javascript API (https://docs.microsoft.com/en-us/azure/cosmos-db/programming#javascript-language-integrated-query-api)

Assuming there is a document in the database with the body.id = '---' the procedure below correctly return that document. However, if I comment the line 'return found ' and uncomment the lines with 'if (1==1)' then the stored procedure returns an empty result. I tried changing it to if (found){return found;} else{return false;}' - same empty output. Also, same happens if I write 'found = found && (1==1);' after 'let found = c.body.id != null && c.body.id ==t;'

Is this a Javascript bug or me doing something wrong?

// SAMPLE STORED PROCEDURE
function sample() {
    __.filter(c=>{
        //return true;
        let t = "---";

        let found = c.body.id != null && c.body.id ==t;


  return found; <---
    //if (1==1){
    //    return found;
    //}

}
, {pageSize: -1}, 

    (a, b, c)=>{

        __.response.setBody(b);
            return;
    });
}
1

1 Answers

0
votes

I reproduce your issue on my side.

The following JavaScript constructs do not get optimized for Azure Cosmos DB indices:

Control flow (for example, if, for, while) Function calls

Based on the statement in the doc, if is not recommanded to use in predicateFunction.

You could just filter documents by return expression(e.g. x.isMetadata === true);