Mongoid query nested embed document through belongs to and embeds many
Victor Hazbun

Victor Hazbun @victorhazbun

About: Founder at @BonsaiLabs

Location:
Colombia
Joined:
Jun 22, 2019

Mongoid query nested embed document through belongs to and embeds many

Publish Date: Apr 27 '21
2 0

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?

Comments 0 total

    Add comment