Sorry for the coffee-script.
Pulling my hair out with this one. I have a schema similar to this:
reviewSchema = Schema
title: String
meta:
author: String
date: String
article: String
tags: [
type: Schema.Types.ObjectId
ref: "Tag"
]
images: [
type: Schema.Types.ObjectId
ref: "Image"
]
attr:
appearance: String
aroma: String
flavor: String
from: String
grade: String
lineage: String
name: String
overall: String
packaging: String
pickupdate: String
price: String
reason: String
story: String
type: String
Review = mongoose.model 'Review', reviewSchema
I also have some data which I have assembled into some JSON files with corresponding data. When I go to make a new schema I look into that file and grab the JSON and create a new review object by:
thisReview = new Review json, minimize: false
If I console.log the json prior to creating 'thisReview' I see that my 'attr' key is properly filled with data but if I console.log 'thisReview' or check the database, I receive NO results for the 'attr' key of my documents. 'attr' is completely ignored.
I went as far as making sure each JSON file's JSON.attr object had each key from the schema with a "" (empty) string for those which didn't exist. The other nested objects like the meta object of the schema are populating perfectly.
Any idea what is happening?
Extra Info: When I get rid of the key/value pairs within the attr object and instead assign: attr: Schema.Types.Mixed
Then all of the data is successfully saved including the empty ("") strings.
Any help would be much appreciated.
The type property of attr is likely tripping up Mongoose to thinking attr is a string instead of an embedded object. Use a more explicit definition for the property, like this:
attr:
appearance: String
aroma: String
flavor: String
from: String
grade: String
lineage: String
name: String
overall: String
packaging: String
pickupdate: String
price: String
reason: String
story: String
type:
type: String