I have two models:
const UserSchema = new mongoose.Schema({
username: String,
name: String
})
const PostSchema = new mongoose.Schema({
title: String,
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
}
})
I know I can query a single Post like:
Post.findById(ID).populate('user')
But how do I query a user with all the posts? I know I could do two seperate queries and put them together, but is there a way to do this with the mongoose api itself?