why am I unable to get value of string in mongoose query?

I am getting data after decoding the base64 string into JSON and it is like this.

{
  List1: [ 'mk singh', 'saurav kashsyap' ],
  List2: [
    { labelName: 'Location', values: ['India','America','Japan'] },
    { labelName: 'gender', values: ['male'] }
  ]
}

I need 2nd element of List2 which is { labelName: ‘gender’, values: [‘male’] } and if I want to find all users from userProfiles which has field as labelName’s value (from above List2) and value is anything from corresponding labelName’values array (from above List2). which will be identical to userProfiles(‘Location’:{$in:[‘India’,’America’,’Japan’]} Here is userProfiles Schema:

   { "_id" : "6123e7ahdhdfdj334733",
    "name" : "Mohit Kumar",
    "gender" : "male",
    "Location" : "India",
    },
   { "_id" : "6123e7ahdhdfdj334731",
    "name" : "saurav  Kashyap",
    "gender" : "male",
    "Location" : "Nepal",
    },
   { "_id" : "6123e7ahdhdfdj334720",
    "name" : "Shaline",
    "gender" : "female",
    "Location" : "america",
    },

and here is my code

app.get("/getresult", (req, res) => {
    let b64string = req.query.filters;
    let buf = Buffer.from(b64string, 'base64');
    let asciiData = buf.toString('ascii'); //into ascii character
    let parseData = JSON.parse(`${asciiData}`); // parsed JSON string

    let field = parseData.List2[1].labelName; // gender
    let value = parseData.List2[1].values; //['male']
    user_profiles.find({
        [field]: {$in:[value]}
    }, (err, result) => {
        if (!err) {
            res.send(result);
        }
    })
});

but I am getting an empty array(result). I don’t know where I am doing wrong. Please help.

Answer

Your value variable is already an array so you you need to change your code to:

user_profiles.find({
    [field]: { $in: value } // instead of { $in: [value] }
}