Mongoimport json文件更新或覆盖..?

时间:2022-10-01 01:53:37

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

我有DB的名称是“Project”,集合名称是“sample”然后我使用mongoimport命令插入一个JSON文件。

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.

现在我编辑了相同的JSON文件。因此,如果要将相同的JSON文件导入到Collection,那么我将面临问题,例如创建了多个实例并且没有进行更新。

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

有没有办法使用mongoimport命令更新或覆盖mongodb中已存在的数据?

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

请注意,我也尝试使用--mode = upsert标志:

./mongoimport --db Project --collection sample --mode=upsert --file   /home/rule.json

3 个解决方案

#1


10  

For MongoDB v3.x,

对于MongoDB v3.x,

--mode=upsert

#2


4  

Default behavior says skip if already exists so by default it wont overwrite existing data.

默认行为表示如果已经存在则跳过,因此默认情况下它不会覆盖现有数据。

But you can update it using --upsert flag.

但您可以使用--upsert标志更新它。

#3


1  

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

--drop标志也可以与mongoimport命令一起使用来覆盖/更新现有数据。

--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.

我给出了这个解决方案,因为我尝试使用--upsert标志,但我看不到现有数据的任何变化,而是创建了新实例。

#1


10  

For MongoDB v3.x,

对于MongoDB v3.x,

--mode=upsert

#2


4  

Default behavior says skip if already exists so by default it wont overwrite existing data.

默认行为表示如果已经存在则跳过,因此默认情况下它不会覆盖现有数据。

But you can update it using --upsert flag.

但您可以使用--upsert标志更新它。

#3


1  

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

--drop标志也可以与mongoimport命令一起使用来覆盖/更新现有数据。

--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.

我给出了这个解决方案,因为我尝试使用--upsert标志,但我看不到现有数据的任何变化,而是创建了新实例。