0
var LocationSchema = new mongoose.Schema({'type': { type: String }, coordinates : []},{_id:false});


var EventsSchema = new mongoose.Schema({
    title:String,
    status:String,
    location:[new mongoose.Schema({
        ll:[LocationSchema],
        type:String
    },{_id:false})] ,
});

添加文档的代码:

function (req,res) {
   var event = new Events();
   var sLoc = new Location();
   var dLoc = new Location();

   event.title = req.body.title;
   event.startdate = req.body.startdate;

   sLoc.coordinates.push(parseFloat(req.body.slong));
   sLoc.coordinates.push(parseFloat(req.body.slat));
   sLoc.type= "Point";

   dLoc.coordinates.push(parseFloat(req.body.dlong));
   dLoc.coordinates.push(parseFloat(req.body.dlat));
   dLoc.type = "Point";

   event.location.push({ll:sLoc,type:"s"});
   event.location.push({ll:dLoc,type:"d"});

   event.save();
}

当我尝试保存文档时,它给出了一个错误 - “无法从对象中提取地理键,格式错误?:{ 0: { type: [ -122.1251274, 37.4096933 ] } }”

我正在使用 nodejs 在 mongoosejs 中进行上述查询

请让我知道我做错了什么。

4

0 回答 0