MongoDB 2dSphere索引嵌入式文档

时间:2013-08-25 22:42:00

标签: mongodb mongoose geospatial

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]}}”

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

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

0 个答案:

没有答案