Lets Say I have a mongo database of messages that looks like this:
{
"_id": ObjectId("5458009c1ab2354c029d7178"),
"to": "dan",
"from": "wood",
"message": "hi dan how are you?",
"time": new Date(1415053468590),
"__v": 0
}
{
"_id": ObjectId("545800b45eaf364d026c1cba"),
"to": "wood",
"from": "dan",
"message": "hi wood how are you?",
"time": new Date(1415053492125),
"__v": 0
}
{
"_id": ObjectId("5458009c1ab2354c029d7178"),
"to": "billy",
"from": "wood",
"message": "hi billy how are you?",
"time": new Date(1415053468590),
"__v": 0
}
{
"_id": ObjectId("545800b45eaf364d026c1cba"),
"to": "wood",
"from": "billy",
"message": "hi wood how are you?",
"time": new Date(1415053492125),
"__v": 0
}
So how can I retrieve the last message from each conversation that the user "wood" may have?
Someone else has already posted a similar question on how to do this in mysql. I am asking how to do this in mongoose.
I will post that for reference incase it helps: Private messaging system. Listing last message of each conversation
Would be great if you could help me out. Thank you for your help. I really appreciate it. I am new to mongoose,mongodb and node.js. I come from a php mysql background.
Would be great if you could post actual code of how to do it so I can try it out and provide feedback. Thanks.
My database schema looks like this:
var messageSchema = new Schema({
to: { type: String, required: true},
from: { type: String, required: true},
message: { type: String, required: true},
time : { type : Date, default: Date.now }
});
proof of what kind of people run this site: http://i62.tinypic.com/bbntx.jpg
Leaving this website as you can tell what kind of unfriendly people are running this site. Ill probably ask somewhere else. They don't actually care about helping you. They care about their rules. Your a new person they don't welcome you. Id be welcomed anywhere else not treated like dirt like people do here.