Hello! This is a cross post from
Stack Overflow I posted few hours ago.
I'm looking for a way to add a validator to a collection such that an embedded document inside the main Mongo document could be entirely absent or if it's present a few of its attributes must be present.
I played around with the $or operator specifying that the `user` embedded document is not required (with the $exists operator set to false) OR the `name` field of the `user` embedded document is present and of $type `string`.
Apparently I'm not able to insert an empty document {} into such a collection as it throws a "Document failed validation" error.
What's wrong with the usage of query operators used in this validator? Please ask if you need more information. Thank you!