I've just started to do my first steps in MongoDB so please do excuse me if my question would sound a bit stupid for you. I really tried my best to google the answer but so far failed to find one.
I wanted to ask what could be the good practice to handle the following situation. For example, I have collection "companies" (means the list of legal entities). Each document in it would have the same common fields like "name_official", "name_short", "name_group", "name_parent", etc.. Field "name_parent" supposed to reference the parent company (different document) in the same collection. Since not all the companies in collection are supposed to have any parent company, logically this field should be "required: false". I understand that I can easily keep the value type of this field as string. But is it possible to assign an ObjectID type to this field which would reference to _id Field of the document that holds information about parent company?
Thanks in advance for your help!
/* Update */ After experimenting with different ways of populating my MongoDB (importing from csv, via "create new company" form in my app, and with the help of specially written "populatedb.js" module) I finally came to conclusion that such a schema (with cross-document referencing within the same collection) doesn't allow to leave "name_parent" field empty. Even if you explicitly define it "required: false". So, instruction below doesn't work. comp_ParentName: {type: Schema.Types.ObjectId, ref: 'company', required: false}
Please, any other advises on the best practices on how to handle this kind of relationships? Once again what I want to do is to reference Parent Company (one legal entity and one document) to Child Company (separate legal entity and separate document) in the same collection "companies".
Really need a help! Thanks in advance!