0

I have a User collection with an embedded Address collection. I want to find or initialize a document with user email and embedded document address' field zipcode. Both these queries return the user object independently.

User.find_or_initialize_by(email: "contact@yahoo.com")
User.find_or_initialize_by("address.zipcode": "14421")

However, the following query does not return an object

User.find_or_initialize_by(email: "contact@yahoo.com", "address.zipcode": "14421")

I can't figure out why.

mohakjuneja
  • 161
  • 3
  • 6

1 Answers1

0

You can try this

User.all_of({:'address.zipcode' => '14421'}, {:email => 'cantact@yahoo.com'})

Hope that helps!

Rajdeep Singh
  • 17,621
  • 6
  • 53
  • 78