How do I get unique elements in this array?

前端 未结 6 1060
时光取名叫无心
时光取名叫无心 2021-01-30 06:11

Using Mongoid. Unfortunately, Mongoid does not allow for selecting unique / distinct! Have gotten these results. As you can see, there are 7 results. If you look carefully (at

6条回答
  •  逝去的感伤
    2021-01-30 06:51

    You can just use the method uniq. Assuming your array is ary, call:

    ary.uniq{|x| x.user_id}
    

    and this will return a set with unique user_ids.

提交回复
热议问题