So by this you mean defining only the room as a reference in Item and not the other way around, leaving only the name field in Room?
Yep, exactly that
:
// This is the simplified mongoose Schema
item = {
name: String,
room: { type: ObjectID, ref: 'Room' },
// Other properties
}
room = { name: String }
Well no, hopefully the objects in a room are not even a hundred
In that case, don’t worry about it and leave it as it is.
Check out what I did on my project (cloned from yours). This would be the result from GET /rooms:
[
{
"objects": [
{
"description": "Lorem ipsum...",
"invoiceNumber": "",
"purchaseDate": "2020-10-07T00:00:00.000Z",
"_id": "5f7dd5fcdf3f2800c5f7fb2f",
"name": "Item 1",
"room": "5f7dd46ddf3f2800c5f7fb2c",
"supplier": "5f7dd5d4df3f2800c5f7fb2e",
"inUse": false,
"createdAt": "2020-10-07T14:51:40.274Z",
"updatedAt": "2020-10-07T14:51:40.274Z",
"__v": 0
},
{
"description": "Lorem ipsum...",
"invoiceNumber": "",
"purchaseDate": "2020-10-07T00:00:00.000Z",
"_id": "5f7de9d1c22cf603bb0fc92a",
"name": "Item 4",
"room": "5f7dd46ddf3f2800c5f7fb2c",
"supplier": "5f7dd5d4df3f2800c5f7fb2e",
"inUse": false,
"createdAt": "2020-10-07T16:16:17.465Z",
"updatedAt": "2020-10-07T16:16:17.465Z",
"__v": 0
},
{
"description": "Lorem ipsum...",
"invoiceNumber": "",
"purchaseDate": "2020-10-07T00:00:00.000Z",
"_id": "5f7dea6631bea903e1f3820b",
"name": "Item 2",
"room": "5f7dd46ddf3f2800c5f7fb2c",
"supplier": "5f7dd5d4df3f2800c5f7fb2e",
"inUse": false,
"createdAt": "2020-10-07T16:18:46.787Z",
"updatedAt": "2020-10-07T16:18:46.787Z",
"__v": 0
}
],
"_id": "5f7dd46ddf3f2800c5f7fb2c",
"name": "Room X",
"__v": 0
}
]