在 MongoDB 中删除数据的最佳实践是什么?
我想使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论