How do you check if an embedded document exists for a document using mongoid in Ruby on Rails? Say I have a document user that has name, email, and might have a nicknames embedded document. Right now if I run user.first.nicknames and if that user doesn’t have the nicknames embedded document in it, it will error out. I’ve tried matches? and exists? but they don’t work.
Thanks!
This should return true if it doesn’t exist
User.first.nicknames.nil?and this will return true if it does exist:User.first.nicknames.present?