DEV Community

Victor Hazbun
Victor Hazbun

Posted on • Updated on

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)