How do I get unique elements in this array?

前端 未结 6 1045
时光取名叫无心
时光取名叫无心 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:58

    For those hitting this up in the future, you can now use the Mongoid::Criteria#distinct method from Origin to select only distinct values from the database:

    # Requires a Mongoid::Criteria
    Attendees.all.distinct(:user_id)
    

    http://mongoid.org/en/mongoid/docs/querying.html (v3.1.0)

提交回复
热议问题