Using mongoose, I want to search for subdocuments that have a certain property and return the most recent one.
// the relevant part of the user schema
id: String,
__history__: {
reply: []
}
// the components of a 'reply' (not defined by a schema)
id: String,
createdAt: Date,
props {
tipID: String
}
Given a specific user id
, I want to search their reply[]
s for replies that have a tipID
in their props
. I then want to return the tipID
for the reply
that has the most recent createdAt
.
I'm new to - well - coding in general. Would love any pointers on how best to tackle this.