You should take a look at the $in
operator in MongoDB.
Use it with a find, then, to make your request faster, you can use the lean
method : with it, mongoDB will return JS objects and not Mongoose model/objects.
YourModel.find({storeID: {$in: storeIDarray }}).lean().exec(yourCallback);
Then, you can use the reduce
method on the resulting array :
yourResult.reduce((acc, el) => acc.concat(el.sensorID), []);
Hope it helps,
Best regards
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…