Я создаю приложение для геоархии.Я уже сделал это с помощью MongoDB, но я изо всех сил пытаюсь сделать это с помощью Sequelize.Я создал схему в MongoDB, как показано ниже.
const GeoSchema = new Schema({
type: {
type: String,
default: 'Point'
},
coordinates: {
type: [Number],
index: '2dsphere'
}
});
const UserSchema = new Schema({
name: {
type: String,
required: [true, 'Name field is required']
},
geometry: GeoSchema
});
И ниже приведен код для поиска местоположений в базе данных:
router.get('/users', async (req, res, next) => {
try {
const users = await User.aggregate([
{
$geoNear: {
near: {
type: 'Point',
coordinates: [parseFloat(req.query.lng), parseFloat(req.query.lat)]
},
distanceField: 'dist.calculated',
maxDistance: parseFloat(req.query.maxDistance),
spherical: true
}
}
]);
if (users.length <= 0) {
return res
.status(200)
.send({ message: 'No users found within your range' });
} else {
return res.status(200).send(users);
}
} catch (error) {
console.log(error);
}
});
Пожалуйста, помогите реализовать те же вещи, используя Sequelize.