I want to traverse and find the current location of users by near. But can not query within users.currentlocation.
My schemas;
const UserSchema = new Schema({
name: { type: String, default: '' },
surname: { type: String, default: '' },
email: { type: String, default: '', },
salt: { type: String, default: '' },
hashed_password: { type: String, default: '' },
interested: { type: [String] },
about: { type: String },
currentcheckin: {type:Schema.Types.Mixed, ref: 'Checkin', index:'2d'},
createdAt: {type:Date, default:Date.now},
searchable: {type:Boolean, default:false}
});
const CheckInSchema = new Schema({
user: { type: Schema.Types.ObjectId, ref: 'User' },
createdAt: { type: Date, default: Date.now },
loc: {
type: [Number],
index: '2d',
default: [0, 0]
},
range: { type: Number, default: 0 },
listable: {type:Boolean, default:true},
});
My query structure is;
With this query, i want to get the users who is near each other. I do not want to store the current locations of users in a seperate collection or marking the documents as currentLocation. I want to traverse only users not all the checkins.
exports.searchable = async(function*(req,res,next){
req.user.searchable = req.body.searchable;
//const scanneds = undefined;
try{
const checkin = Checkin.load(user.currentcheckin);
var coords = [];
coords[0] = 23.600800037384033,
coords[1] = 46.76758746952729;
var currentcheckins = yield User.find({
'currentcheckin.loc':
{
$near: coords,
$maxDistance: 100
}});
//yield req.user.save();
return respond(res,currentcheckins,200);
}catch(err){
//return next(err);
}
});
But query holds and not responding, thanks,