Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried the following with the latest mongoose and it did work for me. Which version are you using? And as for the { type: {type: String } } question, I believe it is because type is also a mongoose keyword type:</p> <pre><code>var zipSchema = new mongoose.Schema({ zc_code : String, zc_population : Number, zc_households : Number, zc_housevalue : Number, zc_householdincome : Number, zc_statecode : String, zc_state : String, zc_city : String, zc_cityname : String, modified_at : Date, center: { type: {type:String}, coordinates: [Number] } }) zipSchema.index({ center: '2dsphere' }); var zipInfo = { zc_code: '78746', zc_population: 26928, zc_households: 10839, zc_housevalue: 344000, zc_householdincome: 100571, zc_latitude: '30.295657', zc_long: '-97.813727', zc_statecode: 'TX', zc_state: 'Texas', zc_city: 'AUSTIN', center: { type: 'Point', coordinates: [-73.7567, 42.6525] } } var Zip = mongoose.model('Zip', zipSchema); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function callback () { Zip.create(zipInfo, function(err) { if (err) console.log(err); mongoose.disconnect(); }) }); </code></pre> <p>The result was:</p> <pre><code>&gt; db.zips.find().pretty() { "zc_code" : "78746", "zc_population" : 26928, "zc_households" : 10839, "zc_housevalue" : 344000, "zc_householdincome" : 100571, "zc_statecode" : "TX", "zc_state" : "Texas", "zc_city" : "AUSTIN", "_id" : ObjectId("522e2df92aacd22e89000001"), "center" : { "type" : "Point", "coordinates" : [ -73.7567, 42.6525 ] }, "__v" : 0 } &gt; db.zips.getIndexes() [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "test.zips", "name" : "_id_" }, { "v" : 1, "key" : { "center" : "2dsphere" }, "ns" : "test.zips", "name" : "center_2dsphere", "background" : true, "safe" : null } ] &gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload