I have a Client schema that contains one of the properties: services, which is an array.
Client.Schema
const clientSchema = mongoose.Schema({
compName: { type: String, required: true },
....
....
services: [{
servName: String,
servCat: String,
freq: String,
fees: Number,
dueDay: Number,
dueMonth: Number,
}]
});
I need to write a query which will return all the clients that have at least one service in the services array. I tried the below query but it gives me an error The expression evaluated to a falsy value:↵↵ assert.ok(!isNaN(val))
mongoose Query
const clients = await Client.find({ 'services': { $size: { $gt: 0} } }).lean().sort('compName');
what would be the correct mongoose query for this? pls help.