i trying details of nearest users(selected users)
var listdata = db.blooddonarmodel.find({_id:{$in:donarids}}, {location: { $near: [83.307974, 17.716456]}}).limit(10)
the mysql equivalent query like
select * users user_id in (1,2,3) , (distance logic);
what correct query result, can correct me?
update:
i have tried these queries, result highlighted respective colored box
note: have added index
db.blooddonars.ensureindex({location:"2d"})
thanks
you don't need explicit $and
in case. quote the documentation:
mongodb provides implicit , operation when specifying comma separated list of expressions. using explicit , $and operator necessary when same field or operator has specified in multiple expressions.
so, can group several conditions in same query object here:
var listdata = db.blooddonarmodel.find( { _id:{$in:donarids}, location: { $near: [83.307974, 17.716456]} }).limit(10)
this match document having both _id
in donarid
, location
near [83.307974, 17.716456]
.
of course, explained in doc, $near
requires geospatial index on location
field. example:
> db.blooddonarmodel.createindex({location: "2d"})
Comments
Post a Comment