Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
How to make field key unique which does not have name in mongodb?

My json to create a record in mongodb is as follows:

{
    'timestamp': {
        'elasticsearch': {
            'backup_status': 'string',
            'backup_folder': 'string',
        },
        'mongodb': {
            'backup_status': 'string',
            'backup_folder': 'string',
        },
        'postgresdb': {
            'backup_status': 'string',
            'backup_folder': 'string',
        },
        'overall_backup_status': 'string',
    },
};

Here the key "timestamp" holds a different value each time, I would like to make this field unique. I have tried check various documentations where I see examples on how to make a field unique by its name but here the field I need to make unique does not have name.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

There is no built in way to preserve uniqueness in key names, What I suggest is you maintain an additional fields that will contain those key names, then you can build a unique index on it.

for example your object should look like this:

{
    unique_keys = [ 'elasticsearch.backup_status', 'elasticsearch.backup_folder'],
    'timestamp': {
        'elasticsearch': {
            'backup_status': 'string',
            'backup_folder': 'string',
        },
    },
};

On every update you need to maintain the unique_keys field accordingly. Now you can build a unique index on unique_keys, this will protect you from having duplicates as required.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!