GithubHelp home page GithubHelp logo

mongodbinc-interns / mongoose Goto Github PK

View Code? Open in Web Editor NEW

This project forked from automattic/mongoose

2.0 2.0 0.0 17.24 MB

MongoDB object modeling designed to work in an asynchronous environment.

Home Page: http://mongoosejs.com

JavaScript 93.60% Shell 0.64% CSS 5.76%

mongoose's People

Contributors

agnek avatar aheckmann avatar bnoguchi avatar bratchenko avatar brettz9 avatar cginzel avatar ciaranj avatar cleishm avatar diogogmt avatar ebensing avatar geoah avatar gitfy avatar jacques-bernier avatar jameshfisher avatar jerem avatar justmoon avatar karneasada avatar niemyjski avatar nw avatar obeleh avatar paulwe avatar pgherveou avatar rauchg avatar regality avatar risseraka avatar tj avatar tomseago avatar treygriffith avatar vedmalex avatar ykumar6 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mongoose's Issues

MongoDB, retrieve documents in a given range with $geoNear

Hello I am sorry to post an issue here but I am quite desperate and I am wondering if this is even possible using geoNear from mongoose.

The documents to be retrieved are tutors that have a range (integer value), corresponding to how far they will to move. And if a customer look for a tutor in 48 rue de Varenne, Paris, for example, we're supposed to retrieve only the tutors that can go to 48 rue de Varenne, Paris (the distance between the search location (queryLon, queryLat) and the tutor location must be less than the tutor range)

I am wondering how to do that ? The query is a latitude and a longitude (location) and the tutor also has a location (lat and lng) and a range (how far he is able to go).

Here is the simplified tutor model :

import mongoose from 'mongoose';
  import validate from 'mongoose-validator';
  import { User } from './user';
  import mongooseAggregatePaginate from 'mongoose-aggregate-paginate';
  
  var ObjectId = mongoose.Schema.Types.ObjectId;
  
  
  var tutorSchema = mongoose.Schema({
      location: {
          address_components: [
              {
                  long_name: String,
                  short_name: String,
                  types: String
              }
          ],
          description: String,
          lat: Number,
          lng: Number
  
      },
      range: {
          type: Number,
          default: 15
      },
      loc: {
          type: { type: String },
          coordinates: []
      }
  });
  
  tutorSchema.plugin(mongooseAggregatePaginate);
  tutorSchema.index({ "loc": "2dsphere" });
  module.exports = {
      Tutor
  };

And here is my query so far :

aggregate = Tutor.aggregate([
   {
     "$geoNear":
     {
       "near":
       {
         "type": "Point",
         "coordinates": [queryLon, queryLat]
       },
       "distanceField": "distance",
       "spherical": true
     }
   },
   {
     $match: match
   }
 ]);

Could you please tell me if this is possible and if so, how ? If not, it would be a great feature to implement :)
Thank you for your help !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.