Need advice to design database in mongodb with mongoose

后端 未结 2 1481
独厮守ぢ
独厮守ぢ 2020-12-12 06:04

I have 2 collections: Hospital and Patient. This month the patient is examination at hospital A, But next month, this patient is examination at hospital B. So when updating

2条回答
  •  心在旅途
    2020-12-12 06:34

    Mongodb does not allow specific joins like a sql based db. I would recommend creating a your hospital collection schema as needed (most likely just basic types such as strings and numbers) and then store a list of visits or examinations with the date and location as part of your patient schema (see: https://mongoosejs.com/docs/schematypes.html#arrays). While you cannot enforce at a database level that the examination location is a valid hospital, you could certainly enforce this in your code.

提交回复
热议问题