简体   繁体   English

在实时 mongodb 机器上更新(或替换)整个数据库集合的最佳方法是什么?

[英]What is the best way to update (or replace) an entire database collection on a live mongodb machine?

I'm given a data source monthly that I'm parsing and putting into a MongoDB database.我每月都会收到一个数据源,我正在解析并放入 MongoDB 数据库。 Each month, some of the data will be updated and some new entries will be added to the existing collections.每个月都会更新一些数据,并在现有的 collections 中添加一些新条目。 The source file is a few gigabytes big.源文件有几 GB 大。 Apart from these monthly updates, the data will not change at all.除了这些每月更新之外,数据根本不会改变。

Eventually, this database will be live and I want to prevent having any downtime during these monthly updates if possible.最终,该数据库将上线,如果可能,我希望在这些每月更新期间防止出现任何停机时间。 What is the best way to update my database without any downtime?在不停机的情况下更新我的数据库的最佳方法是什么?


This question is basically exactly what I'm asking, but not for a MongoDB database. 这个问题基本上正是我要问的,但不适用于 MongoDB 数据库。 The accepted answer there is to upload a new version of the database and then rename the new database to use the old one's name.接受的答案是上传新版本的数据库,然后重命名新数据库以使用旧数据库的名称。 However, according to this question , it is impossible to easily rename a MongoDB database.但是,根据这个问题,不可能轻松地重命名 MongoDB 数据库。 This renders that approach unusable.这使得该方法无法使用。

Intuitively, I would try to iteratively 'upsert' the entire database using each document's unique 'gid' identifier (this is a property of the data, as opposed to the "_id" generated by MongoDB) as a filter, but this might be an inefficient way of doing things.直观地说,我会尝试使用每个文档的唯一“gid”标识符(这是数据的属性,而不是 MongoDB 生成的“_id”)作为过滤器,迭代地“更新”整个数据库,但这可能是一个低效的做事方式。

I'm running MongoDB version 4.2.1我正在运行 MongoDB 版本 4.2.1

Why do you think updating the data would mean downtime?为什么您认为更新数据意味着停机?

It sounds like you don't want your users to be able to access the new data mid-load.听起来您不希望您的用户能够在负载中访问新数据。

If this is the case, a strategy could be to have 2 databases;如果是这种情况,策略可能是拥有 2 个数据库; a live and a staging;现场和分期; rather than renaming the staging database to live, you could just rename the connection string in the client application(s) that connect to it.与其将登台数据库重命名为实时数据库,不如只重命名连接到它的客户端应用程序中的连接字符串。

Also consider mongodump and mongorestore to copy databases;还可以考虑使用mongodump和mongorestore复制数据库; although these can be slower with larger databases.尽管对于较大的数据库,这些可能会更慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在现场计算机上更新(或替换)整个数据库表的最佳方法是什么? - What is the best way to update (or replace) an entire database table on a live machine? 在 mongoDB 中实现 FIFO 集合的最佳方法是什么? - What is the best way to implement a FIFO collection in mongoDB? 保留数据时更新实时数据库的最佳方法? - Best way to update a live database while persisting data? 什么是插入/更新数据到数据库的最佳方法 - What is the best way insert/update data to the database 客户端应用程序立即对数据库中的更新做出反应的最佳方式是什么? - What's the best way for the client app to immediately react to an update in the database? 归档实时 MySQL 数据库的最佳方式 - Best way to archive live MySQL database 什么是创建此数据库的最佳方法 - what is the best way to create this database 什么是实现此数据库的最佳方法 - What is the best way to realize this database 跟踪本地数据库更改以部署到实时数据库的最佳做法是什么? - What is the best practice to track local database changes for deploy on live database? 使用 noSQL 和 MongoDB 在数据库中存储任何类型文件的最佳方法是什么 - What is the best way to store any kind of file in a database using noSQL and MongoDB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM