mongodbinc-interns / mongoose Goto Github PK
View Code? Open in Web Editor NEWThis project forked from automattic/mongoose
MongoDB object modeling designed to work in an asynchronous environment.
Home Page: http://mongoosejs.com
This project forked from automattic/mongoose
MongoDB object modeling designed to work in an asynchronous environment.
Home Page: http://mongoosejs.com
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 !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.