flipdiggity
flipdiggity

Reputation: 35

Find by sub-documents field value with case insensitive

I know this is a bit of newb question but I'm having a hard time figuring out how to write a query to find some information. I have several documents (or orders) much like the one below and I am trying to see if there is any athlete with the name I place in my query.

How do I write a query to find all records where the athleteLastName = Doe (without case sensitivity)?

{
    "_id" : ObjectId("57c9c885950f57b535892433"),
    "userId" : "57c9c74a0b61b62f7e071e42",
    "orderId" : "1000DX",
    "updateAt" : ISODate("2016-09-02T18:44:21.656Z"),
    "createAt" : ISODate("2016-09-02T18:44:21.656Z"),
    "paymentsPlan" :
    [ 
        {
            "_id" : ObjectId("57c9c885950f57b535892432"),
            "customInfo" :
            {
                "formData" :
                {
                    "athleteLastName" : "Doe",
                    "athleteFirstName" : "John",
                    "selectAttribute" : ""
                }
            }
        }
    ]
}

Upvotes: 1

Views: 59

Answers (1)

Sede
Sede

Reputation: 61273

You need to use dot notation to access the embedded documents and regex because you want case insensitive.

db.collection.find({'paymentsPlan.customInfo.formData.athleteLastName': /Doe/i}

Upvotes: 1

Related Questions