猫鼬填充,然后在附近找到$附近

时间:2019-06-28 08:10:58

标签: node.js mongoose

嘿,我有2种猫鼬模型

SUBRUB模型

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

const geoSchema = new Schema({
    type:{default:"Point",type:String},
    coordinates:{type:[Number],index:"2dsphere"}
})

// set up a mongoose model and pass it using module.exports
var model  = new Schema({

    name: {type:String,unique:true}, 
    postal:{type:String},
    location:geoSchema

});

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



module.exports = mongoose.model('Suburb', model);

请求模型

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



var model  = new Schema({
     name:String,
     suburb:{type: Schema.ObjectId, ref: 'Suburb',required:true},

}, {
    timestamps:true
});




module.exports = mongoose.model('Trequests', model);

我需要从某个位置附近的请求模型中找到所有请求。请求的位置是郊区ID。

谁能告诉我如何实现这一目标。 谢谢

0 个答案:

没有答案