2016-12-09 5 views
0
var dishSchema = new Schema({ 
    name: { 
     type: String, 
     required: true, 
     unique: true 
    }, 
    image: { 
     type: String, 
     required: true 
    }, 
    category: { 
     type: String, 
     required: true 
    }, 
    label: { 
     type: String, 
     default: "", 
     required: true 
    }, 
    price: { 
     type: Currency, 
     required: true 
    }, 
    description: { 
     type: String, 
     required: true 
    }, 
    comments:[commentSchema] 
}, { 
    timestamps: true 
}); 

Следующий код - это моя схема, которую я пишу для курса Coursera на узле JS, Express и MongoDB. Я получаю ошибку проверки на ярлыке схемы, а цена и изображение не отображаются при публикации. Есть ли причина, вот данные, которые я опубликовал.Ошибка схемы Mongoose

{ 
    "name": "Zucchipakoda", 
    "image": "images/zucchipakoda.png", 
    "category": "appetizer", 
    "label": "", 
    "price": "1.99", 
    "description": "Deep fried Zucchini coated with mildly spiced Chickpea flour batter accompanied with a sweet-tangy tamarind sauce" 
} 

Любая помощь в определении возможных причин для этого оценивается.

ответ

1

Этикетка должна иметь значение, поскольку вы отмечаете ее как обязательное поле в своей схеме. Если вы не хотите вводить какое-либо значение в ярлык, тогда удалите его из него и не передадите его в качестве ключа при отправке данных.

Ваша схема может быть:

var dishSchema = new Schema({ 
    name: { 
     type: String, 
     required: true, 
     unique: true 
    }, 
    image: { 
     type: String, 
     required: true 
    }, 
    category: { 
     type: String, 
     required: true 
    }, 
    label: { 
     type: String 
    }, 
    price: { 
     type: Currency, 
     required: true 
    }, 
    description: { 
     type: String, 
     required: true 
    }, 
    comments:[commentSchema] 
}, { 
    timestamps: true 
}); 

Помещенные данные, как это:

{ 
    "name": "Zucchipakoda", 
    "image": "images/zucchipakoda.png", 
    "category": "appetizer" 
    "price": "1.99", 
    "description": "Deep fried Zucchini coated with mildly spiced Chickpea flour batter accompanied with a sweet-tangy tamarind sauce" 
} 
+0

на самом деле, я узнал, что это просто необходимо, чтобы быть одинарные кавычки вместо двойных кавычек для значения поля метки по умолчанию. Спасибо за помощь. – tcoulson