suvankar
suvankar

Reputation: 1558

Join two mongoid criteria

I have an array with two Mongoid::Criteria

[#<Mongoid::Criteria
      selector: {"news_category_id"=>"1"},
      options:  {:sort=>[[:published_date, :desc]], :limit=>1},
      class:    News,
      embedded: false>
    , #<Mongoid::Criteria
      selector: {"news_category_id"=>"2"},
      options:  {:sort=>[[:published_date, :desc]], :limit=>1},
      class:    News,
      embedded: false>
    ]

How can I get one Mongoid::Criteria object from that array of criteria?

When that array rendered , it contains "Array of Array of json objects" and I want an array of json objects. (single merged array of json)

Upvotes: 2

Views: 3239

Answers (3)

Rahul Chandra
Rahul Chandra

Reputation: 583

You can use:

criteria1.concat(criteria2) #this worked for me. 

Upvotes: 2

suvankar
suvankar

Reputation: 1558

the array, which contains "Array of Array of json objects" to make a "Array of json object" i have come up with the following solution

array_of_criteria.collect { |aoc| aoc.to_a}.flatten

Upvotes: 1

Related Questions