2016-12-13 46 views
1

我知道這是一個新問題,但我很難搞清楚如何編寫查詢來查找某些信息。我有幾個文檔(或命令),非常類似於下面的文檔,我試圖查看是否有任何運動員具有我在查詢中放置的名稱。通過子文檔查找字段值不區分大小寫

如何編寫一個查詢來查找所有記錄的運動員姓名= Doe(不區分大小寫)?

{ 
    "_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" : "" 
       } 
      } 
     } 
    ] 
} 
+0

'db.collection.find({ 'paymentsPlan.customInfo.formData.athleteLastName':/ DOE/I})' – styvane

回答

1

您需要使用點表示法來訪問embedded documentsregex因爲你想不區分大小寫。

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