mongorestore命令替换现有记录? [英] mongorestore command replace existing records?

查看:218
本文介绍了mongorestore命令替换现有记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mongorestore是否可以替换数据库中现有的记录而不是跳过它(这是默认行为)?

Is there a way for mongorestore to replace the records existing in the database instead of skipping it which is the default behavior ?

我当前正在使用最新的2.4.x版本的mongodb.

I'm currently using the latest 2.4.x version of mongodb.

推荐答案

否.来自 mongorestore :

如果还原到现有数据库,则mongorestore将仅插入现有数据库,并且不执行任何类型的更新.如果现有文档在目标数据库和集合中具有相同的_id值字段,则mongorestore不会覆盖这些文档.

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.

如果要使用mongorestore完全覆盖数据库或数据库中的集合,请删除数据库或集合(选中

If you want to completely overwrite the database or a collection within the database with mongorestore, drop the database or collection (check --drop parameter as pointed out by vikas's answer). If you want to replace certain documents or merge duplicate documents, then you'll need to write your own script to do the restore and implement the more complex logic yourself.

这篇关于mongorestore命令替换现有记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆