hello I have two collection one called room and second called booking I have RoomID as a attribute and I want to link room id as a primary key from collection room with RoomID in collection booking in mongoose with express and node JS one room has many booking...?
There is nothing such concept of Primary Key
in mongodb (mongoose) but in Relational Databases like: MySQL, PGSQL and so on.
Even if you want to do so, you can use that in find operation simply like:
const bookings = await BookingModel.find({RoomID: inputRoomID});
This way you can get bookings for a simple room with inputRoomID
and If you want to go further ie bookings for all rooms, go for aggregation
in mongoose.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.