0
votes

I would need to have something like this

{
    event : "something",
    location : [
        {
            long:25, lat:34
        }.
        }
            long:25, lat:35
        }.
        .
        .
        .
    ]
}

Is this possible? And is it possible to have a geospatial index for the location field? I would have queries with $nearSphere.

Thanks

EDIT: mongoose schema question

having the schema entry be something like location : [{ lon : Number, lat: Number}] gets me to end up with an aditional _id for each object in the location array. Is that 1. a problem? 2. a nuissance? 3. something that i can fix?

ex : { "lon":1, "lat":2, "_id":"50bfeea2a3092d1d67000007" },

1
I would use , instead of . between the location array elements :). but seriously, why wouldn't work, have you tried? Check Geospatial Indexing in the manual, it sounds me exactly what you want.balazs
I've been reading it three times already and just now I saw the damn Spherical true part for geoNear. You can answer the question if you want to so I can accept it for future reference.pocorschi
Actually I should amend the question with an actual problem in Mongoose. Please check edit.pocorschi
I see @JohnnyHK already answered your edited question,balazs

1 Answers

2
votes

If you don't want each of the location elements to have an _id field, you can disable that by explicitly defining a schema for the elements with the _id option set to false.

Like this:

var testSchema = new mongoose.Schema({
    event: String,
    location: [new Schema({long: Number, lat: Number}, {_id: false})]
});