I am using Node.js with mongoose together with Typescript. And based on SO threads like this queries should work with my function as well:
let conditions = {};
conditions['belongsToRestaurant'] = dto.restId;
conditions['belongsToRestaurant']
await Order.findOne({conditions}).then((doc) => {
console.log('doc');
console.log(doc);
})
The console always logs the proper value for "restId", and always null for "doc".
I have tried every single variation I could think of. I created an object with a constructor, created an object with a set property, tried with classes nothing worked. I tried using mongoose types, such as:
conditions['consumerName'] = new mongoose.Schema.Types.String("asasd");
conditions['belongsToRestaurant'] = mongoose.Types.ObjectId(dto.restId);
Nothing has worked so far. Thx for reading and help in advance!
- Sidenote: Keep in mind these fields I am referencing are not in array, or in a subdocument or anything of that nature. And work completely fine when I am not using objects to update.