mongodb - 将mongo集合导入现有集合而不覆盖它

是否可以将 mongodump 导入到现有集合中添加(而不是覆盖它)?如果是,如何?

它会使用 mongoimport --db mydb 吗?

这些集合在结构上是相同的,但很简单,它们具有来自同一应用程序的不同实例的不同数据集。我想将所有数据合并到一个数据库中。

最佳答案

使用mongorestore .

仅当您指定 --drop 时才会覆盖集合范围。因此,如果您什么都不做,它只会添加新元素(从而按照您的意愿行事)。

如果您有相同的 _id 元素,可能会出现唯一的问题,在这种情况下,它将忽略它们。

If you restore to an existing database, mongorestore will only insert into the existing database, and does not perform updates of any kind. If existing documents have the same value _id field in the target database and collection, mongorestore will not overwrite those documents.

https://stackoverflow.com/questions/29740348/

相关文章:

sql-server - 在任务管理器中误杀了sqlserver.exe进程,如何重启?

logging - 日志不打印完整的堆栈跟踪

sql - 如何在外键约束中使用两列

ruby - 我在哪里可以看到我的浏览器发送的 http 请求

php - Symfony cron 作业,奇怪的错误

css - padding-top 不起作用,但 padding-right 是

scala - Apache Spark 1.3 dataframe SaveAsTable 数据库

macos - 将 MAC 上远程桌面中的下移控制向下箭头发送到 Windows PC

c - 为什么我在使用 fgets 时必须输入 EOF 3 次?

sql - 使用当前连接从 sql 存储过程调用 dll 函数