Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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']}});
like image 326
Jie Avatar asked May 18 '15 04:05

Jie


1 Answers

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) { /* ... */});
like image 126
victorkt Avatar answered Oct 20 '22 00:10

victorkt