使用 Mongoid / Ruby 获取所有子文档
我在 MongoDB 中有一个这样的文档结构:
User
|---> Posts
|----> Comments
因此,父文档 User
具有嵌入的 Post
文档集合,它本身具有嵌入的 Comment< 集合/代码> 文件。
我拿回了 User
文档,现在整个文档树都在内存中,如下所示:
user = User.where(username: 'test').first
从 user
中,我如何获取所有评论的列表?
I have a document structure in MongoDB like this:
User
|---> Posts
|----> Comments
So, a parent document User
with a collection of embedded Post
documents, which itself has a collection of embedded Comment
documents.
I grab the User
document back and now have the entire document tree in memory, like so:
user = User.where(username: 'test').first
From user
how can I get a list of all the comments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情:
或者
Try something like this:
Or