getting "MongoError: n/a" error when trying to find() with $near query

124 views
Skip to first unread message

John Lim

unread,
Jun 12, 2015, 9:47:48 AM6/12/15
to mongod...@googlegroups.com
i'm trying to get result near to a certain coordinate. however i'm not able to get this done, what i get is empty array although the query is execute successfully. here's my code 

var userSchema = new db.Schema({
  email: { type: String, unique: true, lowercase: true },
  password: { type: String, select: false },
  company_name: String,
  location_verified: { type:Boolean, default:false},
  account_verified: { type:Boolean, default:false},
  date_joined: {type:Date, default:Date.now},
  business_details: {
    business_phone: String,
    business_email: String,
    business_location:[]
  }
})
userSchema.index({ 'business_detail.business_location': '2d' });
var User = db.model('User', userSchema);

above is my userSchema, and below is the query i'm trying to perform. 

 var limit = req.query.limit || 10;
    // get the max distance or set it to 8 kilometers
    var maxDistance = req.query.distance || 8;
    // we need to convert the distance to radians
    // the raduis of Earth is approximately 6371 kilometers
    maxDistance /= 6371;
    // get coordinates [ <longitude> , <latitude> ]
    var coords = [];
    coords[0] = 101.6833;
    coords[1] = 3.1333;
    // find a location
    User.find({
      'business_details.business_location': {
        $near: coords,
        $maxDistance: maxDistance
      }
    }).limit(limit).exec(function(err, locations) {
      if (err) {
        console.log("The ERROR:"+err);
        //return res.json(500, err);
      }
      console.log("The RESULT:"+locations);
      //res.json(200, locations);
    });
and i'm getting this 


may i know why ? your help is appreciated. thanks

John Lim

unread,
Jun 12, 2015, 9:51:32 AM6/12/15
to mongod...@googlegroups.com

even when i deleted the maxDistance i'm still getting the same result 
Message has been deleted

John Lim

unread,
Jun 15, 2015, 2:56:51 AM6/15/15
to mongod...@googlegroups.com
i have posted an update of the question on stackoverflow and i still can't get it done. i really don't get it .


On Friday, 12 June 2015 21:47:48 UTC+8, John Lim wrote:

Asya Kamsky

unread,
Jun 15, 2015, 9:45:00 PM6/15/15
to mongodb-user
I see someone on SO spotted that your index was on the field "business_detail" but query was on "business_details".

I'm sure I've wasted hours myself looking for something that had to be obvious but not being able to see it.  :)

Asya


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d1478147-685a-4f65-a67e-8d034014c7d1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages