I’ve got:
class Article
include Mongoid::Document
embeds_many :comments
end
class Comment
include Mongoid::Document
embedded_in :article
end
Since Comment is an embedded document in Article. How would I list down ALL Comments in order of created_at?
Should I structure it so that Comment is not an embedded in Article or is there a way with the above schema?
If you’re trying to query comments out of context of their articles, then clearly comment should be a top level entity and not embedded one.
In embedded case you can use map-reduce or aggregation framework. Regular query language won’t help you here.