简体   繁体   中英

Add field with dash character in Mongoose schema

I want to add a field to a schema which includes dash character ( - ) in it. Mongoose is not allowing it. Is this possible or not?

var mySchema = new Schema({
  family-name: {
    type: String, 
    default: ''
  }
});

Just add quotes around the property name:

var mySchema = new Schema({
  'family-name': {
    type: String, 
    default: ''
  }
});

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