-1

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
    ]
}

So I want to get only the emails.address with the first character in uppercase.

krlzlx
  • 5,752
  • 14
  • 47
  • 55
LisaN
  • 165
  • 2
  • 2
  • 13

1 Answers1

0

Use can use regex like javascript:

db.humans.find({'emails.address': /^[A-Z]/})

If you have many emails in your array, but only want to returned matched email (start with upper case letter), you can use additional projection:

db.humans.find({'emails.address': /^[A-Z]/}, {emails: {$elemMatch: {'address': /^[A-Z]/}}})
Mạnh Quyết Nguyễn
  • 17,677
  • 1
  • 23
  • 51