Trouble Evaluating String in Realm Function

I have a basic function containing this code:

  const body = EJSON.parse(payload.body.text());
  if(body[i].userID == ""){
        var id = BSON.ObjectId(body[i].objectID);
        coll.deleteOne({"_id": id});

My webhook is receiving an array of objects (This code is inside a for loop, the “i” indexing works fine). If the userID field of the object is null/an empty string, then I want to delete that object. Any suggestions? I feel like this is really simple.

Hi @Joewangatang,

Isn’t your condition needs to be as follows:

var toDelete = false;
 if( !body[i].userID ){ 
    toDelete = true;
else  if (body[i].userID.toString() == "") {
     toDelete = true;

 If (toDelete){


1 Like

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