I’m facing difficulty in getting documents whose value is gte than the input value.
const searchQuery = req.query;
const fieldsCount = Object.keys(searchQuery);
if (fieldsCount[0] === “experience”) {
const searchResult = await Members.find({ experience: { $gte: ${Object.values(searchQuery)[0]}
} });
return res.status(200).json(searchResult).end;
}
I have 4 members in db, with exp 1, 2, 3, 4.
So above query should return 2 documents. But its returning 0 documents.
Below is the schema of the collection
const membersSchema = new mongoose.Schema({
employee_id: {
type: Number,
required: [true, “Please enter a value”],
},
employee_name: {
type: String,
minLength: [3, “Employee Name Should have at least 3 characters”],
required: [true, “Please enter a value”],
},
technology_name: {
type: String,
required: true,
},
experience: {
type: Number,
required: [true, “Please enter a value”],
min: 0,
},
});
1