Usman Khan
Usman Khan

Reputation: 147

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: ''
  }
});

Upvotes: 1

Views: 1135

Answers (1)

Andrew Li
Andrew Li

Reputation: 57954

Just add quotes around the property name:

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

Upvotes: 5

Related Questions