I would like to use Mongoose to find a record of data in MongoDB Atlas. The aqlLevel and batchSize is the value that already know, but inspectionLevel, lotSizeMin and lotSizeMax is the field of one of the table in MongoDB Atlas. I’ve tried the syntax that without where condition and it works. However, with the where condition I can’t get anything back from the table in MongoDB Atlas. Can anyone help me with the Mongoose syntax so that I can find the data with where condition?
The piece of code that I would like to use to search
let aqlLevel = find.aqlLevel;
let batchSize = find.batchSize;
let findSampleSizeCodeLetter = await SampleSize.find({inspectionLevel: aqlLevel})
.where(batchSize).gte({lotSizeMin}).lte({lotSizeMax}).exec();
The schema of the table is like this below:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const schema = new Schema({
lotSizeMin: { type: Number},
lotSizeMax: { type: Number},
inspectionLevel: {type: String},
sampleSizeCode: {type: String}
}, { collection : 'SampleSizeCodeLetter' });
schema.set('toJSON', {
virtuals: true,
versionKey: false,
transform: function (doc, ret) {
delete ret._id;
delete ret.hash;
}
});
module.exports = mongoose.model('SampleSizeCodeLetter', schema);
2
Answers
My code below successfully solve my problem:
use this code both code
or this one