I ma returning journals back from Mongo using node , can I iterate over the response object (array or journals) and then add properties on them.
for (i=0; i < results.lenth ; i++){
if (results[i].viewedThi.index of (mee)){
result.newProperty = "seen this!";
}
}
Excusing my code syntax I was wondering if I may do this or is there a more elegant way. I want node to look through each journals list of viewers and then add a "viewed this" property to each one before returning it to the client. I want to use this new property for my client's templating
1)QUERY MONGO 2)Get objects that represent enity 3) look through array property of object for value 4)if value found add a property to denot that value has been found
ex: Mongoose returned
book =[
{title:"bird book1", readers ['james', 'nick'] }
{title:"bird book2", readers ['max', 'kevin'] }
{title:"bird book3", readers ['blake', 'rick', 'manny'] }
]
I want to look through the books and then turn them to
book =[
{title:"bird book1", iReadThis: true},
{title:"bird book2", iReadThis: false},
{title:"bird book3", iReadThis: true}
]
My intent is to add a property before returning the journals to the user. The property identifies a piece of context pertinent to the user.