0

I have a document with this structure

{
    name : "...",
    ...,
    ...,
    ...,
    hours : {
        standard : {
            ...
        }
}

I need to add:

{
    holiday : {
        ...
    }
}

inside the hours document and end up with:

{
    name : "...",
    ...,
    ...,
    ...,
    hours : {
        standard : {
            ...
        },
        holiday : {
            ...            
        }
    }
}

I tried running

{
    $set : {
        hours : {
            holiday : {
                ...            
            }
        }
    }
}

but that simply replaced my standard with holiday inside of hours. How can I achieve this?

Thanks!

1 Answer 1

3

Try this instead:

db.collection.update(query, {$set: {'hours.holiday': {...}}});
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much! (by the way this taught me the harsh lesson of why you test a query on a test db FIRST)
you should make backups also :)
I forgot I actually made one this morning. I am in good shape :) Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.