简体   繁体   中英

Mongoose.js - array of geospatial locations

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" },

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})]
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM