A
A
Artem Taranoff2016-04-08 08:13:01
NoSQL
Artem Taranoff, 2016-04-08 08:13:01

How to search in Mongo by key and value throughout the document?

Good afternoon.
It is necessary to find all the people who graduated from, for example, institute 567.
The problem is that we cannot accurately specify the parent elements for this institute (and are at different levels).
For example, in professions.actor. theater.drama and professions.actor. stuntman is 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,
                }
            },
        }
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
KkJ, 2016-04-08
@ArtemTaranoff

No way.
You have a strange database structure.
Is it the same person who studied to be a theater comedian and a movie comedian?

A
Andrei, 2016-04-08
@VladimirAndreev

this is what happens when they try to cram relational data into a non-relational unstructured database ...
relational easily solves this problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question