DEV Community

Victor Hazbun
Victor Hazbun

Posted on • Edited on

1 1

Mongoid query nested embed document through belongs to and embeds many

Given the following documents, I'm trying to find a log document given a token ID.

class Log
  include Mongoid::Document

  belongs_to :user
end

class User
  include Mongoid::Document

  embeds_many :tokens
end

class Token
  include Mongoid::Document
end
Enter fullscreen mode Exit fullscreen mode

I tried Log.where('user.tokens._id': BSON::ObjectId('123ABC') with no luck. Any ideas?

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay