So I'm working on a blog app, and I'm coding an online editor right now, nothing fancy.
Before I start to explain my problem consider this schema which I'm using :
var blogSchema = restful.model('blog-schema', mongoose.Schema({
title: String,
preview: String,
content: [{tag: String, body: String}],
comments: [{ body: String, date: Date}],
createdAt: {type: Date, default: Date.now}
}
On my client side, I'm using react to POST data which looks like this :
[{"type":"h2","body":"azeaeazeae"},{"type":"p","body":"azeaeazeae"}]
Then within express() I do this :
blogSchema.update(
{title: "please work AGAIN"},
{
$pushAll: {
content: test
}
},
function(err, stat, docs) {
console.log(stat);
}
)
Then with POSTMAN I check if the data is well stored and I got this :
"content": [
{
"tag": "[object Object],[object Object]",
"_id": "57b2eced869e03821d446c38"
}
My question, how in my server can I iterate through this array of object and then push every single item to its respective place : tag and body.