var LocationSchema = new mongoose.Schema({'type': { type: String }, coordinates : [Numbers]},{_id:false});
var EventsSchema = new mongoose.Schema({
title:String,
status:String,
location:[new mongoose.Schema({
ll:[LocationSchema],
type:String
},{_id:false})]
});
Code to add a document:
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();
}
I event tried:
Events.create({location:[{ll:[{type:"Point" ,coordinates:[1 ,1]}],'type':'s'},{'type':'d',ll:[{type:"Point",coordinates:[2,2]}]}]},function(err){
if (err){
}
});
I am still getting error. Not sure what is wrong in my query or schema. I tried in MongoDB terminal and it works if my 'll' parameter is not an array.
But I need to have 'll' as an array in moongoosejs because I want it as an embedded document.
Please help me or at least point me in right direction. I am kind of stuck for a long time
When I try to save the document, it give an error -- "Can't extract geo keys from object, malformed geometry?:{ 0: { type: [ -122.1251274, 37.4096933 ] } }"
I am making above query in mongoosejs with nodejs
Please let me know what I am doing wrong.