Closed kkrishnan90 closed 5 years ago
I'm not sure I understand the question, can you provide some specific examples of what your geojson objects look like?
Here's a couple relevant links: https://mongoosejs.com/docs/geojson.html http://thecodebarbarian.com/80-20-guide-to-mongodb-geospatial-queries
Basically, I have the follow json schema
{
driver_name:String,
start_location:{type:Point, coordinates:[]}
end_location:{type:Point, coordinates:[]}
start_date:Date,
start_time:Date,
seats:Number
}
Now a let's say, I have a rider who searches for a trip (inputs a start and end location). Now I have to query all drivers who match the rider's search location (both start and end point as given). At this point, I need to query a geojson (driver's schema) based on both start and end location of another geojson (rider's schema).
Sorry, I hope I'm clear to you now ? If not, let me know. I shall explain a bit more on this.
Is Point
a custom type? I suspect not, I'm guessing your schema definition should be:
start_location: { type: { type: 'string' }, coordinates: ['number'] }
Yeah, that's fine on the schema part. Can you show some snippet to query multiple location based geoNear ? Like say, geoNear based on both start and end location.
@kkrishnan90 I'm not sure I understand your question, can you please clarify?
Hi @vkarpov15 , sorry for such a delayed response. The objective of my mongoose query is to find trips that are matching close to the start and end location. For example, a driver creates a trip from location A to B .. now when a passenger is searching for a trip, I need to query based on the location matching or closest location. So when a passenger is searching by his start and destination location, I would like to query the database based on the closest match of both start and destination of trips created by driver.
@kkrishnan90 To support this query, I'd create a separate collection called TripPoint
and create separate documents for trip start and trip end. That would make this query much simpler and faster.
@kkrishnan90 Did you find the solution? If yes please drop the snippet here or describe briefly how you solved. am also looking for the same scenario to query. Thanks
Hey guys ! Thanks a ton for such an awesome library ! I have a simple scenario and not sure if mongoose supports such query on geoJSON data.
I have a start and end location and a couple of more location objects as stop points intermediary to the start and end location geoJSON.
I have been thinking a lot about how to query multiple locations with geoNear or say near method through which when I match my documents based on start and end location if it matches.
Can someone explain on this please ? Thanks to all in advance.
P.S. I have searched all over the internet(stackoverflow especially) and I haven't found solution to this specific problem. So expecting some wizards guidance :stuck_out_tongue_winking_eye: