简体   繁体   中英

How can i insert data to a schema array in nodejs?

I have a schema as shown below and I was trying to insert a value to that schema but data is not being assigned. How we can assign data to a schema array in nodejs? building is my schema instance.

my schema is shown below

geoValues: [
        {
            latitude: Number,

            longitude: Number,

    }
    ],

I tried like below for assigning data to my schema

building. geoValues.latitude = latitude;
 building. geoValues.longitude = longitude;

Check whether your mongoose schema looks like this,

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const buildingSchema = new Schema({
  geoValues: [{
    latitude: Number,
    longitude: Number
  }]
});

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