Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoimport json file update or overwritte ..?

I'm having DB which name is "Project" and collection which name is "sample" then I inserted one JSON file using mongoimport command.

Now i edited the same JSON file. So if want to import the same JSON file to the Collection then I am facing the problem like multiple instances are created and no updating is not taking place.

Is there any way to update or overwrite the data already present in the mongodb using mongoimport command ?

Note that I also tried using --mode=upsert flag:

./mongoimport --db Project --collection sample --mode=upsert --file   /home/rule.json
like image 940
Mercer Avatar asked Apr 21 '15 14:04

Mercer


People also ask

Does Mongoimport overwrite?

you can use upsert which will overwrite the existing. (erase+ import = overwrite with new data.)

What is Mongoimport?

The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport , or potentially, another third-party export tool. Run mongoimport from the system command line, not the mongo shell.


2 Answers

For MongoDB v3.x,

--mode=upsert
like image 78
lanenok Avatar answered Oct 19 '22 14:10

lanenok


--drop flag also can be used along with mongoimport command to overwrite/update the existing data.

--drop


./mongoimport --db Project --collection sample --drop --file   /home/UCSC_rule.json

I gave this solution because i have tried using --upsert flag but i could not see any changes in the existing data instead new instance was created.

like image 22
Abdulvakaf K Avatar answered Oct 19 '22 14:10

Abdulvakaf K