I have 2 models in Next.js app, Booking and User. Obj bellow is booking obj. When User booked some dates, new obj in booking is created. When user open booking details page, should see details of booking. I have a problem to select a specific object that belongs to the user. I was trying this, and it shows me all objects:
_id: ObjectId(64b8440c8ff8e8950641fd7e) // id of boooking obj
user: ObjectId(64b4cd15d0ef7c21d80ecd4d) // id of user
in front end
const { user } = useSelector((state) => state.userAuth)
const userID = user?.user?._id
than I am using this userID to find specific obj
const res = await axios.post('/api/bookingDetails/bookDetails', userID, config )
// config is headers: {"Content-Type": "application/json"}
and in backend this code
const id = req.body.userID
const user = await Booking.find( id )
res.status(200).json({
message: 'success ',
user
})