我想从一个对象集合中获得一个记录结果,但是在遵循Mongoid文档之后,我不知道还有更多的尝试。为什么elem_match返回0个元素?
我有这样的一个元素:
> contacts
=> #<Contact _id: 55ace6bc6xx, device_fields: {"app_id"=>"55ace6bc65195efc8200xxxx"}, created_at: 2015-07-20 12:17:00
UTC, updated_at: 2015-07-20 12:17:00 UTC, name_first: "Kory",
name_last: "Funk", ...>
此匹配器的列表:
> apps = []
> apps << App.where(id: "55ace6bc65195efc8200xxxx").first.id
=> ["55ace6bc65195efc8200xxxx"]
而这个代码试图获得匹配的元素:
> contacts.elem_match(device_fields: {:app_id.in => apps }).to_a
=> []
> contacts.elem_match(device_fields: { "app_id": "55ace6bc65195efc8200xxxx"}).to_a
=> []
为什么返回一个空数组,它有一个匹配?
你可以试试'contacts.elem_match(device_fields:{“app_id”:apps.first})。to_a'吗? –
是的,结果相同。我尝试了这个以及很多可能的组合......我无法得到正确的回复 –