I am running node.js server (with express & jade) and mongodb database. I have a function where I query mongodb using findOne. The document is about a user along with an array element that has their preferences. So the schema looks like this...
var userSchema = mongoose.Schema({
username : { type: String, index: true },
preferences : [{
_id : mongoose.Schema.ObjectId,
title : String,
color : String,
shape : String,
}]
});
UserTabs.findOne({ 'username' : userID }, function(err, data) {
//How do I manipulate data.preferences to change array order....
}
I pass data.preferences object to jade and print the array content list.
Question: Within the findOne function how can I manipulate the data.preferences object so I can re-arrange the array element's order and then pass the new object back to jade? BTW: what object type is this data?
FYI - I do not want to change the order in the database.