Currently, I am in the process of developing a blog application and working on an online editor feature. The schema I'm using for this project is outlined below:
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}
}
For the client-side implementation, I am utilizing react
to POST data in the following format:
[{"type":"h2","body":"azeaeazeae"},{"type":"p","body":"azeaeazeae"}]
In my server side code with express()
, I have the following logic:
blogSchema.update(
{title: "please work AGAIN"},
{
$pushAll: {
content: test
}
},
function(err, stat, docs) {
console.log(stat);
}
)
After checking the stored data with POSTMAN, I noticed that the output was as follows:
"content": [
{
"tag": "[object Object],[object Object]",
"_id": "57b2eced869e03821d446c38"
}
The challenge I am facing now is how to iterate through this array of objects on the server side and correctly push each item to its designated place within the tag
and body
fields.