Whenever I try to store a location in my mongodb it doesn't show, so I guess I'm doing something wrong. I can't find any documentation on how to store a location in mongoose so I'm just gonna ask it here.
I first create my model:
var eventSchema = mongoose.Schema({
name : String,
creator : String,
location : { type: [Number], index: '2dsphere'},
});
Then I try to add it to my database:
var newevent = new event({
name: name,
creator: tokenUser,
location : { type: "Point", coordinates: [longitude, latitude] },
});
When I look in my database everything is stored except the location ...
I fixed it myself.
I did this in my model:
loc : { type: {type:String}, coordinates: [Number]},
Underneath I made it a 2dsphere index.
eventSchema.index({loc: '2dsphere'});
And to add data to it:
loc: { type: "Point", coordinates: [ longitude, latitude ] },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With