Find by geolocation & fulltext search terms @mongodb 2.6

96 views
Skip to first unread message

Salines

unread,
Apr 17, 2014, 11:49:46 AM4/17/14
to mongoo...@googlegroups.com
Hi all, I have one beginner question.

Let's say that my mongo document looks like this:

{
_id: ....,
name: "...",
 loc : { type : "Point" ,
          coordinates : [ 40, 5 ] 
},
commets: [
  {
    author:...
    post:"....."
  },
 
]
}

How to properly write a query that will only scan and select documents released within 20 kilometers that contain the search words in the comments?

Please if you know some tutorial, post a link here.

Thanks

William Riley-Land

unread,
Apr 17, 2014, 5:02:17 PM4/17/14
to mongoo...@googlegroups.com
Hi Salines,

I believe you would use something like this:

mongoose.model(‘thing’).find({
  loc: { 
    $near: {
      $geometry: { type: ‘Point’, coordinates [42,55] },
      $maxDistance: 234
    }
  },
  comments: {
    $text: { $search: ‘keyword’ }
  }
});

Here is the documentation for these query operators:

There are other ways to go about this, like using the geoNear command, but hopefully this is enough to get you started!

Cheers,
William

William P. Riley-Land
https://linkedin.com/in/willprl
Founder & REST API Engineer
Kun.io App Studio LLC
(573) 823-2607

--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Salines

unread,
Apr 17, 2014, 6:37:42 PM4/17/14
to mongoo...@googlegroups.com
Thanks ..
Reply all
Reply to author
Forward
0 new messages