I use mongodb and mongoid gem and I'd like to get some advice.
I have an app where User has many
Markets and Market has many
Products.
I need to search for the products, say in a specific price range, in all (or any) the markets which belong to the user.
Which relation fits better for this, embedded or referenced?
I currently use referenced and it looks like so
class User
has_many :markets
end
class Market
belongs_to :user
has_many :products
end
class Product
belongs_to :calendar
belongs_to :user
end
And for search, I use this query
Product.where(user_id: current_user.id).
in(market_id: marked_ids).
where(:price.gte => price)
I'm curious, since mongdb is a document oriented database, would I benefit in a performance or design, if I used embedded documents in this situation?