如何使用正则表达式查询MongoDB?

时间:2018-07-26 11:03:58

标签: mongodb mlab

humans.json

{
    "_id": "22YAE7bEXdST9MyrZ",
    "createdAt": {
        "$date": "2016-11-22T15:09:25.968Z"
    },
    "abilities": {
        "power": {
            "mana":78,
            "chakra":0
            "energy":60
        }
    },
    "emails": [
        {
            "address": "Rob6@rob.com",
            "working": false
        }
    ],
    "roles": [
        "killing":true
    ]
}

所以我只想获取第一个字符为大写的emails.address

1 个答案:

答案 0 :(得分:0)

使用可以像javascript一样使用正则表达式:

None

如果阵列中有许多电子邮件,但只想返回匹配的电子邮件(以大写字母开头),则可以使用其他投影:

2018-07-27 09:03:41,189 INFO sqlalchemy.engine.base.Engine INSERT INTO emp_man_history (emp_id, man_id_from, man_id_to, "when") VALUES (?, ?, ?, ?)
2018-07-27 09:03:41,189 INFO sqlalchemy.engine.base.Engine ('2', None, '1', '2018-07-27 09:03:41.188906')