0
我有一個集合(稱爲員工),它包含多個文檔。每個文檔具有以下fields-
{
"name":"John",
"designation":"Product manager",
"departmentID":['abpqr','def']
}
{
"name":"David",
"designation":"Senior s/w Engg",
"departmentID":['abc','lmn']
}
{
"name":"Mathew",
"designation":"ODC head",
"departmentID":['abpyz','xyz']
}
現在我想一個蒙戈查詢來獲取僱員在其DepartmentID的從「ABP」開始的列表。它應該是喜歡 -
db.Employees.find({DepartmentID的:{$在:{$正則表達式: '^ ABP'}}})
是否有可能通過使用單個查詢來獲取它?如果沒有,那麼獲得結果的備選方案是什麼。我正在使用pymongo,我期待的結果是 -
{
"name":"John",
"designation":"Product manager",
"departmentID":['abpqr','def']
},
{
"name":"Mathew",
"designation":"ODC head",
"departmentID":['abpyz','xyz']
}
謝謝rebenfa!它的工作現在,我認爲$ regex搜索內部列表的原因也沒有提供任何額外的努力。 – Workonphp