I have a postgreSQL database that has 3 tables named customer
, product
and purchase_order
. Every table has id_
as the primary key. Table purchase_order
also has customer_id
(id_
field of customer
table) and product_id
(id_
field of product
table) as foreign keys.
I want to create the same DB on MongoDB. However, I'm not sure how to establish foreign keys. I have researched it and found out that it is pretty much up to me how to do it. So, this is how I did purchase_order
table on MongoDB:
{"_id":{"$oid":"5f5639cdb675b2a13db059b3"},
"customer_id":{"$oid":"5f563a08b675b2a13db059b1"},
"product_id":{"$oid":"5f563a13b675b2a13db059b2"},
"status":false}
My goal is to write a spring application to perform CRUD methods. On postgreSQL, I added foreign key constraints on DB and @OneToMany
& @ManyToOne
annotations on my code to establish foreign keys. However, I'm not sure how to do it for MongoDB. Does my MongoDB document correctly represent the foreign keys? How can I make sure to establish my foreign keys on my spring application for MongoDB?