在 MongoDB 中删除数据的最佳实践是什么?

发布于 2025-01-19 00:57:52 字数 463 浏览 2 评论 0原文

我想使用 PyMongo 和 pyspark 删除 MongoDB 中数百万条数据。

因此,我需要一些最佳实践来从 MongoDB 中删除批量数据,

我认为如下:

首先,使用 Spark DataFrame 从 HDFS 收集数据。 (ex, df.rdd.flatMap(lambda x: x).collect())

其次,将第一个中的所有数据放入“list”变量中。并创建对 mongo 的查询,如 " { "_id" : { "$in": list }} "

第三。使用函数“delete_many()”删除像“{db}.{collection}.delete_many(query)”这样的列表

但是,我认为这看起来很糟糕,因为列表的大小看起来有些问题

我是否将列表削减了数千列出并执行?

这种情况下的最佳做法是什么..?

还有其他做法吗?

I want to delete over millions of data in MongoDB using PyMongo with pyspark.

So, I need some best practice to delete bulk data from MongoDB

I think below

First, Collect the data from HDFS with spark dataframe. (ex, df.rdd.flatMap(lambda x: x).collect())

Second, Put all data from first to 'list' variable. and create query to mongo like " { "_id" : { "$in": list }} "

Third. Use function "delete_many()" to delete the list like "{db}.{collection}.delete_many(query)

But, I think it looks bad practice because it look some problem the size of the list

Do i cut the list thousand of list and execute?

what is the best practice in this situation..?

are there any other practice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文