how do I pass the returned object from geoNear into a callback?

52 views
Skip to first unread message

alia...@tradermail.info

unread,
Jul 16, 2011, 4:03:24 PM7/16/11
to mongodb-user
I have a collection called test that I want to query with geoNear. The
2d index is set on the field loc.

Am I using db.runCommand correctly here?

db.open (err, client) ->
db.collection 'test', (err, collection) ->
db.runCommand {geoNear:"loc", near:[50,50], $maxDistance:1},
#callback here? what params?

I would normally do something like .toArray (err, docs) -> then then
use the found docs but how should I implement the callback when using
geoNear? It already returns an object with meta data right? How do I
access it?

Thanks very much!

Eliot Horowitz

unread,
Jul 16, 2011, 9:07:09 PM7/16/11
to mongod...@googlegroups.com
Which driver are you using?

The geoNear command returns a single doc with a results array.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

alia...@tradermail.info

unread,
Jul 17, 2011, 12:44:47 AM7/17/11
to mongodb-user
I'm writing this in node.js with the node-mongodb-native driver.

(the syntax is coffee-script)

On Jul 16, 9:07 pm, Eliot Horowitz <el...@10gen.com> wrote:
> Which driver are you using?
>
> The geoNear command returns a single doc with a results array.
>
> On Sat, Jul 16, 2011 at 4:03 PM, alias...@tradermail.info

Eliot Horowitz

unread,
Jul 17, 2011, 1:23:02 AM7/17/11
to mongod...@googlegroups.com
How would you normall process the result of a command?

alia...@tradermail.info

unread,
Jul 17, 2011, 9:11:31 AM7/17/11
to mongodb-user
db.open (err, client) ->
db.collection 'test', (err, collection) ->
collection.find({}).toArray (err, docs) ->
#process the docs in this call back


On Jul 17, 1:23 am, Eliot Horowitz <el...@10gen.com> wrote:
> How would you normall process the result of a command?
>
> On Sun, Jul 17, 2011 at 12:44 AM, alias...@tradermail.info

Eliot Horowitz

unread,
Jul 18, 2011, 5:00:50 PM7/18/11
to mongod...@googlegroups.com
So you should be able to do the same thing.
Not sure where you are getting stuck.
Reply all
Reply to author
Forward
0 new messages