1

I have a Mongoid Criteria of users and I want to find a user. Given a user that I'm sure doesn't exists in the criteria:

>> users.where(email: user.email).exists?
=> false

>> users.map(&:id).include?(user.id)
=> false

When I search by id I always get the user instead of nil:

>> users.find(user.id)
=> #<User _id: 521a43b37

>> users.where(id: user.id).first
=> #<User _id: 521a43b37

>> users.where(_id: user.id).first
=> #<User _id: 521a43b37

>> users.where(id: user.id).exists?
=> true

What am I doing wrong?

Thanks in advance.

PS: mongoid (4.0.0.beta1), rails (4.0.1), ruby (2.1.0), mongoDB (2.4.9)

cortex
  • 5,036
  • 3
  • 31
  • 41

0 Answers0