Search mongoose by property in json object field

Say I have a circuit like

var TempSchema = new Schema({
    location: Schema.Types.Mixed
});

json object will be saved

now I want to search for a property inside this field of a json object, can I use the following query?

Temp.find({location.country: {$in: ['US', 'CN', 'JP']}});
+4
source share
1 answer

Yes, you can do this with dot notation , just enclose it in quotation marks:

Temp.find({"location.country": {$in: ['US', 'CN', 'JP']}}, function(err, data) { /* ... */});
+3
source

All Articles