【发布时间】:2019-06-28 20:52:18
【问题描述】:
我收藏了一个类似的样子:
_id:5d0fe0dcfd8ea94eb4633222
Category:"Stripveiling (Nederlands)"
Category url:"https://www.catawiki.nl/a/11-stripveiling-nederlands"
Lot title:"Erwin Sels (Ersel) - Originele pagina"
Seller name:"Stripwereld"
Seller country:"Nederland"
Bids count:21
Winning bid:"€ 135"
Bid amount:"Closed"
Lot image:"https://assets.catawiki.nl/assets/2011/11/17/7/4/c/74c53540-f390-012e-..."
我需要将“中标”字段更改为 int。即移除货币符号并将整个集合从字符串转换为 int。
在文档中我找不到如何做到这一点,我真的必须用 Python 获取每个值,删除货币符号并使用方法更新来做到这一点吗?我有将近 8,000,000 条记录,会很长。
如何使用收集方法做到这一点?或者用 Python 最快的选择是什么?
【问题讨论】:
-
都是“币号”形式的中标吗?
-
@AbdeslemSMAHI 是的
-
int(currency_string[1:].strip()) - 这是假设前两个字符中有一个字符串是货币符号和''空格字符。
-
@MFK34 我用python将字符串转换为int没有问题,特别是因为不需要strip(),你可以只用int()。我不知道如何在 mongodb 中进行所有更新
标签: python-3.x mongodb mongodb-compass