These are chat archives for Automattic/mongoose

6th
Sep 2018
Mohamed Dhaker Abdeljawed
@Mdhaker
Sep 06 2018 09:25
@lineus Hello again, I thought it worked fine, but it seems $all don't compare arrays to be equals, if the values in the query array is in the mongodb array it returns a result, but not for equals
Mohamed Dhaker Abdeljawed
@Mdhaker
Sep 06 2018 09:46
with $all 'contributers.user' is considered as an array but when using it with other operator its an object, like $size for example
Kev
@lineus
Sep 06 2018 10:55
@Mdhaker If I'm understanding you correctly, $size would be called on contributers. like { contributers: { $size: 10 } }
the $all with the dot notation was just because the the query array only had that one field in it.
Berian
@chaiwa-berian
Sep 06 2018 19:22
How can I enforce referential integrity in mongoose, at schema design level? Like when A is deleted and A references B, then B should be deleted or foreign key of A in B should be set to null!
Kev
@lineus
Sep 06 2018 19:29
@chaiwa-berian There really isn't a schema option that will manage references for you automatically, though there might be a mongoose plugin that does. You can write a static or an instance method that will remove docs or references from both sides of the reference though. In the case of calling document.remove() you can write a post-hook that will delete the references/docs on the other side of the reference.
Kev
@lineus
Sep 06 2018 19:37
@chaiwa-berian I wrote this a little while ago for someone on the slack channel. It's basically the same question and answer.
If you wanted to, you could implement a separate node process that watches both collections and reacts to remove events by updating all references to the removed document. This seems like overkill though :smile: