mongo 中所有记录的较低字段 [英] Lower field for all records in mongo

查看:43
本文介绍了mongo 中所有记录的较低字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我的帐户设置如下:

Basically I have the accounts setup like this:

{
 'email': 'Matt@GMAIL.com',
 'others': '...'
}

在 sql 中,我习惯于只搜索 LOWER(email) = LOWER(search) 的位置,但是我发现这在 mongo 中无法轻松(且快速)完成.

In sql, I was used to just searching where LOWER(email) = LOWER(search), however I found that can't easily (and quickly) be done in mongo.

所以我正在尝试做类似的事情:

So I'm trying to do something like:

UPDATE 账户 SET email = LOWER(email);

或:

accounts.update_many({}, {
            '$set': {
                'email': lower(email)
            }
        }, upsert=False)

知道如何在 Mongo 中做到这一点吗?

Any idea how to do this in Mongo?

PS:我使用的是 PyMongo 驱动

PS: I'm using PyMongo driver

推荐答案

我误解了你的问题..我只能使用 python 函数 :)

I missunderstood your question.. i can only purpose a python function :)

def accounts_to_lower():
    for account in accounts.find({'email': {'$exists': True}):
        accounts.update_one({'email': account.get('email'}, {
            '$set': {
                'email': account.get('email'}.lower()
            }
        }, upsert=False)

这篇关于mongo 中所有记录的较低字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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