Jie
Jie

Reputation: 317

mongoose search by a property in a json object field

Let's say I have a schema as

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

location will store a json object

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

Temp.find({location.country: {$in: ['US', 'CN', 'JP']}});

Upvotes: 7

Views: 6262

Answers (1)

victorkt
victorkt

Reputation: 14562

Yes you can do it using the dot notation, just enclose it inside quotes:

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

Upvotes: 8

Related Questions