Mr. Demetrius Michael
Mr. Demetrius Michael

Reputation: 2406

Ruby / MongoDB : Exclude certain results in Find

I'm typically using:

@coll.find({"lang"=>@language,"description"=>@description,"location"=>@location},{:limit=>@results_needed}).to_a

But there are times when I have an array of "_ids", that I don't want to be included in the results. Is there a native way to do that? I've been doing a hack with .delete_if but I would like to keep the database doing as much work as possible.

Upvotes: 1

Views: 280

Answers (1)

oldergod
oldergod

Reputation: 15010

What about

@coll.find(:id.ne => array_of_ids)

or

@coll.find(:id => {:$ne => array_of_ids})

From Not equals in mongo mapper.

Upvotes: 3

Related Questions