0

I have a Model that is called teams.

When I do Teams.account_ids it returns something like:

 [{"_id"=>"145952912234658", "_type"=>"Page"},
 {"_id"=>"465641870160985", "_type"=>"Account"}]

Lets say I want to get all Teams that have one specific account id regardless of its _type.

Something like:

Team.where(some_id.in => account_ids.map{|k| k["_id"))
1
  • What is your question? Commented Sep 1, 2015 at 20:07

1 Answer 1

1

You can use multi-keys to effectively ignore the array when searching and then use the standard "key inside a hash" notation to look at the _ids:

Teams.where('account_ids._id' => { :$in => array_of_ids })
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you @mu_is_too_short! It worked. Could you reference me where to read more about ignoring the array as you have proposed?
The $eq operator docs are probably the best starting point. There used to be a section specifically about this behavior but it seems to have gone away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.