insanoid
insanoid

Reputation: 413

Node.js Mongodb geospatial query with find() issue

usercollection.find({
      "device_info.location" :
            $geoWithin : { $centerSphere :[[_latitude, _longitude]  , 100/3959]}}},
            function (err, result) {
                if (err) callback(err) else callback(null, result)
            });

As you can see it is a simple query for fetching documents that meet the location criteria, this works perfectly fine if I change this to findOne however in this case it just returns {}. The same query works perfectly fine when executed from the terminal. There are two records that are within this range and show up on the terminal as well.

Is there some specific reason why it behaves like this with find()?

Upvotes: 0

Views: 50

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311835

find provides its results to the callback as a Cursor, not an array. If you want an array you need to chain a call to toArray:

usercollection.find({ ...existing query... }).toArray(callback);

Upvotes: 2

Related Questions