S
S
semolex2015-04-25 16:06:08
JavaScript
semolex, 2015-04-25 16:06:08

How to make a multi update in MongoDB, by a given parameter?

Unfortunately, the official documentation is not clear to me yet.
I have the following problem:
There is a database of records, about 1000 records in the following form:

{
    "name": "john",
    "age" : 25,
    "role": 1
}

And there is a JSON file with records where I have the necessary update, for example, for this record:
{
    "name": "john",
    "role": 3
}

the name field is unique. I need to update all the records in the collection using a JSON file... Unfortunately, I can only do it one at a time, but I need to update all the records at once, according to this logic. Is it possible?
That is, it will change all the roles in the entries, using the name as an identifier.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Vasiliev, 2015-04-25
@semolex

db.collection.update({ 'name': "john"}, { $set: { 'role': 3}}, { multi: true})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question