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
you can use upsert which will overwrite the existing. (erase+ import = overwrite with new data.)
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.
For MongoDB v3.x,
--mode=upsert
--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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With