0

Structure of Document:

enter image description here

Mongoose Schema:

var mongoSchema = new Schema({
name:  String,
description: String,
location: { lat: Number, long: Number },
images: [String],
blocks: { text: String, logo: String },
subLocations: {
    name: String,
    description: String,
    location: {
         lat: Number,
         long: Number
    },
    images: [String]
    }
});

Following Query does not work:

mongooseModel.find().
   where('location.lat').equals(18.710145).
   exec(function(err, response) {
}

While this query does work:

mongooseModel.find().
   where('lat').equals("18.710145").
   exec(function(err, response) {
}

Any guidance?

0

2 Answers 2

0

the datatype of the nested lat (location.lat) is a String (look at your embedded image, far right column). that's why your first query didn't work -- you're comparing a Number to a String.

Sign up to request clarification or add additional context in comments.

1 Comment

But I verified that it is casted as a number due to the mongoose defined schema. Also even after converting it to "18.710145" the query does not return any results.
0

Please try below query to find out your result.

db.myCollection.find( { $where: {"location":{"lat":"18.710145"}} } );

1 Comment

This isnt using mongoose, its via the MongoDbClient right?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.