简体   繁体   English

如何在mongodb中获取带有注释的所有文章?

[英]How to grab all articles with comments in mongodb?

How do I grab all articles with comments? 如何获取所有带评论的文章? I have: 我有:

class Article
  include Mongoid::Document

  embeds_many :comments
end

class Comment
  include Mongoid::Document

  embedded_in :article
end

At the moment. 在这一刻。 This seems to work: 这似乎可行:

Article.where(:comments => {"$exists" => true})

Am I using the $exists directive correctly for this context? 我是否在这种情况下正确使用了$exists指令?

存在评论的文章(因此,不是nil)

Article.where(:comments.ne => nil)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM