$geoNear 仅在我给出 maxDistance = 100 * 1000 时才给出结果;

问题描述

我想要附近的律师名单, 我使用了 MongoDB 聚合,但只有当我通过 maxdistance 大于 100km 时它才会给出结果。 如果我想设置 maxdistance = 10 * 1000;那么它没有给出任何结果,但数据库中有可用数据。

这是模型:

const mongoose = require('mongoose')
const Schema = mongoose.Schema;

const lawyerSchema = new mongoose.Schema({
    name: {
        type: String,required: true
    },email: {
        type: String,password: {
        type: String,location: {
        type: { type: String,default: 'Point' },coordinates: { type: [Number],default: [0,0] }
    }
})

lawyerSchema.index({ "location": "2dsphere" });

const Lawyer = mongoose.model('Lawyer',lawyerSchema)
module.exports = Lawyer

这是路线:

//route for find nearby lawyer
router.get("/findLawyer",(req,res) => {
  const long = parseInt(req.query.long);
  const lat = parseInt(req.query.lat);

  Lawyer.aggregate(
    [
      {
        $geoNear: {
          near: {
            type: "Point",coordinates: [long,lat],},distanceField: "dist",mindistance: 10 * 1000,maxdistance: 10 * 1000,distanceMultiplier: 6371,spherical: true,key: "location",],(err,results) => {
      if (err) {
        res.status(400).json({ error: err });
      } else {
        res.status(200).json({ result: results });
      }
    }
  );
});

这是数据库中的记录:

enter image description here

这是我的邮递员:

enter image description here

如果我犯了任何错误,请纠正我。 谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...