How to find the opposite of nil in Rails requests

We are happy to use Mongoidit ActiveRecordas follows:

Task.where(project_id: params[:project_id], archived_at: nil)
# find me the tasks for project_id that haven't been archived

But what is the easiest way to say the opposite?

# find me the tasks for project_id that have been archived
# i.e. where archived_at is not nil

It is impossible to figure out or find out the reverse line of the first line of code. I guess it should be simple :)

+3
source share
1 answer

I think you want to use this:

:archived_at.ne => nil 

Take a look here: MongoId-Matchers-NE

+2
source

All Articles