I'm wondering how an app like Tinder knows to get all the users in a 50miles radius of my location.
I could get my lat/long and then go through every other users lat/long while calculating the distance and only store the ones that are < 50miles but that seems like a horrible way to do it when you're dealing with a big user base.
Say I have a User Schema:
const userSchema = new Schema(
{
username: {
type: String,
required: true,
index: { unique: true },
},
{...}
lat: {
type: Number,
default: 0
},
long: {
type: Number,
default: 0
},
}
);
module.exports = mongoose.model("User", userSchema);
And I have a User info mongodb:
{
"id": "605a652ddg3rdf46b274c8df",
"username": "johnsmith",
"lat": "39.554618",
"long": "-104.911083"
}
And I've got 1000s of other Users just like it. Some with locations within 50miles of johnsmith, others not.
What would be the best/most efficient way to go about getting the users within a certain radius of johnsmith?
I've seen answers specific to Firebase like this but what if I'm using Mongoose/MongoDB?