【问题标题】:mongodb : how to get documents that contains nested field datamongodb:如何获取包含嵌套字段数据的文档
【发布时间】:2013-09-06 06:15:02
【问题描述】:

假设我的数据是

db.posts.save({postid:1,postdata:"hi am ",comments:["nice","whats bro"]});

所以在这种情况下如何迭代 cmets 意思是

cursor=selct * from posts;
cursor 1=selct * from comments where postid=:cursor.postid
for (i in cursor)
for(j in cursor1)

【问题讨论】:

    标签: node.js mongodb


    【解决方案1】:

    迭代 cmets 的一种方法如下:

    db.posts.find().forEach(
      function(doc) {
        // iterate over the comments in your preferred javascript way
        var i;
        for (i=0; i<doc.comments.length; ++i) {
          // Do whatever you want with doc.comments[i] here
        }
      }
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-28
      • 1970-01-01
      • 2016-05-04
      • 2021-12-11
      • 2018-06-03
      • 1970-01-01
      相关资源
      最近更新 更多