I build a blog website with express.js and mongoosejs. A article may have one or more category. When I create a new article, I get error:
{ [CastError: Cast to O
Please use mongoose.Schema.Types.Mixed as data type of categories. I had the same issue with saving data array. It works for me.
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var ArticleSchema = new Schema({
created: { type: Date, default: Date.now },
title: String,
content: String,
summary: String,
categories: [{type: Schema.Types.Mixed }]
});
mongoose.model('Article', ArticleSchema);