If you look at the source in lib / mongoid / finders.rb:
...
def find_or_create_by(attrs = {}, &block)
find_or(:create, attrs, &block)
end
you can see that find_or_create_by takes {}as the first argument. You can simply transfer several conditions at once.
something.find_or_create_by(name: 'john', age: 20)
and it should work.
source
share