$exists query database with incoming payload value and respond

So it might be in the response payload output then?

When testing the response output by swapping the two around I get different outcomes

with this order

    if(result.count > 0 ) {
      
      response.setBody( JSON.stringify({"ok": true,"details": ""}) ); 
      
    } else {
      
      response.setBody(  JSON.stringify({"ok": false,"details": "Sorry not found"}) ); 
      
    }

I get “Sorry not found” for when the value is in the collection and also when it is removed.

and with this order

    if(result.count > 0 ) {
      
      response.setBody(  JSON.stringify({"ok": false,"details": "Sorry not found"}) ); 
      
    } else {
      
      response.setBody( JSON.stringify({"ok": true,"details": ""}) ); 
    }

I get nothing, for both when the value is in the collection and also when it is removed.

Hi Pavel,

now making more use of this console.log() to establish where the problem is further down

I included this line after the two responses before the last }

console.log(result);

I get what seems to be the correct result, but both still outputs the same "Sorry not found” result

This with the listed item:

Logs:

[

"Name : Jonty22",

"1"

]

Function Call Location:

US-VA

and this with item removed from the collection:

Logs:

[

"Name : Jonty22",

"0"

]

Function Call Location:

US-VA

Hi @a_Jn,

Alright I see where the issue is. The count method returns a value and not an object.

Use the following code :

if(result > 0 ) {

        response.setBody( JSON.stringify({"ok": true,"details":"Found"}) );    

      } else {

        response.setBody(  JSON.stringify({"ok": false,"details":"Not Found"}) );

    }

Notice that it use “result” directly.

Best regards
Pavel

Great thanks Pavel, it looks like it is working now! yes think it was in the count

Many thanks Andi

1 Like

Thank u so much for taking time to help.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.