Let's say I have these two models below and i want to get or fetch the location of a specific user using mongoose in node:
User Model
const userSchema = new mongoose.Schema({
name: {
type: String,
minlength: 2,
maxlength: 50,
},
email: {
type: String,
minlength: 5,
maxlength: 255,
unique: true,
},
password: {
type: String,
minlength: 5,
maxlength: 1024,
},
});
And Location Model
const locationtSchema = new mongoose.Schema({
name: {
type: String,
minlength: 5,
maxlength: 50,
},
lat: {
type: String,
required: true,
},
lng: {
type: String,
required: true,
},
user: {
type: userSchema,
required: true,
},
});
So, I tried to resolve it like this... but it didn't work.
const location = Location.find({
'user._id': req.params._id
})
How can i return locaitons of a specific user?