user3531155
user3531155

Reputation: 439

$geoWithin query form mongodb to mongoose statement

Have this query from mongodb:

 db.location.find(
 {loc: { $geoWithin: { $centerSphere: [ [ 9, 9], 
 radius ] } }, action:1 })
 .limit(10)
 .skip(1, function(err,   result) {
    console.dir(result);
 });

How to translate it to mongoose statement with using geoWithin?

Upvotes: 1

Views: 1100

Answers (1)

user3531155
user3531155

Reputation: 439

Well some thing like this:

 LocationModel.where('loc').within({ center: [ your_lat, your_lng], radius: your_radius, unique: true, spherical: true }).where('action').equals(your_action).skip(your_skip).limit(10).exec(
    function(err, result) {
    console.dir(result);
});

befor of course need create LocationModel and LocationSchema, i hope it's can help.

Upvotes: 1

Related Questions