我在数据库中有一个名为 bills 的馆藏。
集合中的每个文档都是在国会中通过的账单。
在每个文档中,都有一个名为 votingRecord 的数组,该数组由作为每个国会议员投票记录的对象组成。
我需要能够在votingRecord array
内排序和查找特定的键/值,而我无法弄清楚。
我尝试了此处列出的示例,但是我的问题是,集合中的每个文档都有由代表组成的嵌套对象数组(“ votingRecord”)。
我需要在查询中设置一个初始过滤器,以便可以在特定的BillingRecord中搜索特定的帐单。
{
"_id" : ObjectId("5dc209b7af26e560a3204bcc"),"bill_id" : "hr676-116","title" : "To reiterate the support of the Congress of the United States for the North Atlantic Treaty Organization,and for other purposes.","sponsorState" : "CA","sponsorParty" : "D","summary" : "NATO Support act This bill prohibits the appropriation or use of funds to withdraw the United States from the North Atlantic Treaty Organization.","primarySubject" : "NATO Support act This bill prohibits the appropriation or use of funds to withdraw the United States from the North Atlantic Treaty Organization.","introducedDate" : "2019-01-17","latestMaction" : "Received in the Senate.","votingRecord" : [
{
"person" : 400440,"state" : "AK","district" : 0,"vote" : "Yea","name" : "Rep. Don Young [R]","party" : "Republican"
},//( five hundred or so of these objects(all reps + senators),ending with)
],"latestMactionDate" : "2019-01-23","__v" : 0
}
我的MongoDB shell没有响应我所做的任何查询。
db.bills.find({"introducedDate": 2019-01-03},{votingRecord: {$elemMatch: {state:"FL"}}})
上面的查询感觉像是最接近的查询,因为我是用“ introducedDate”指定的,但到目前为止还算不上运气。