Good day. It is necessary to find all the people who graduated, for example, Institute 567. The problem is that we can not accurately specify the parent elements for this institution (and are at different levels). For example, in the professions.actor. theatre.drama and in professions.actor. stuntman is an institute

{ "_id": ObjectId("56ff619b14989a0ed0316921"), "firstName": "Иван", "lastName": "Лабанов", "professions": { "actor": { "film": { "drama": { "institute": 567 }, }, "theatre": { "drama": { "institute": 123, }, }, "stuntman": { "institute": 321, } }, } }, { "_id": ObjectId("56fe77b114989a05577e9f22"), "firstName": "Петр", "lastName": "Смирнов", "professions": { "actor": { "film": { "comedy": { "institute": 567, } }, } } }, { "_id": ObjectId("56fe77b114989a05577e9f11"), "firstName": "Василий", "lastName": "Иванов", "professions": { "actor": { "film": { "comedy": { "institute": 123, } }, } } } 

We chose a non-relational precisely because the data is structured, but it has an nesting, which Monga does a great job with. The essence of the task - we have a lot of people of creative professions (and others with them): Actors, Voice, Models, Maykapery. Each of these professions has many areas (theater actor, film actor, circus actors, stuntmen), these areas may have specific specializations (opera and ballet theater, comedy film actor, etc.), and so even a few levels of nesting (education, knowledge of languages, etc.). The difficulty is not just in storage, but in that it is possible to search by these parameters. Here is a real example query:

A man above 180cm, up to 25 years old, a category C driving license, graduated from VGIK, opera soloist (Italian), able to juggle.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

To be honest, the structure you have is a little non-logical and inconvenient. It is better, of course, to think and remake for your specific tasks and search parameters. For example, add the institute key in a fixed place, and add the data there as in an array. There will be duplication of information and problems with maintaining its integrity, but there will be no search problems.

And on the existing structure, I think you can try using mapreduce: in the map function, go through the document to any nesting level and look for the desired key with the appropriate value. And decide whether this document is suitable for you or not.

  • Thank you for your reply. Yes, most likely we will store data similar to the institute in a fixed place. - iceman12