E
E
eellazy2021-06-15 13:21:17
MongoDB
eellazy, 2021-06-15 13:21:17

How to properly create document schema in MongoDB?

Hello!
I'm trying to write a document schema in MongoDB. The number of records at the moment is 8 million. Approximately there will be about 50 million of them. The choice fell on MongoDB because I don’t know the exact structure
There were several questions that I could not find answers to. Though I shoveled a large number of articles.

1. I have JSON markup, but some values ​​in the keys are simply not there. Perhaps they will appear later. Should we store empty values, null values, or just not add this key?

2. One of the fields indicates the category to which this or that contact belongs. Is it better to associate it with the category key or write the category name in the key value?

3. How correct is it to store documents of different structures in a collection?

Example of my json

json = {
    'name': '',
    'date_birth': '',
    'documents': [
        {
            'type': '',
            'seria': '',
            'text': ''
        }
    ],
    'phone': '',
    'email': [],
    'country': '',
    'bio': '',
    'category': [],
    'status_control': [
        {
            'status': '',
            'date': '',
            'cause': ''
        }
    ],
    'status': '',
    'work': [
        {
            'address': '',
            'company_name': '',
            'post': '',
            'period': ''
        }
    ],
    'address': [
        {
            'address': '',
            'index': ''
        }
    ],
    'social_network': [
        {
            'network': '',
            'link': '',
            'login': '',
            'name': '',
            'text': ''
        }
    ],
    'date': {
        'date_added': '',
        'date_edit': ''
    },
    'comment': ''
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question