Save Subset of MongoDB Collection to Another Collection

后端 未结 6 760
名媛妹妹
名媛妹妹 2020-11-30 22:37

I have a set like so

{date: 20120101}
{date: 20120103}
{date: 20120104}
{date: 20120005}
{date: 20120105}

How do I save a subset of those d

6条回答
  •  情书的邮戳
    2020-11-30 23:25

    Here's the shell version:

    db.full_set.find({date:"20120105"}).forEach(function(doc){
       db.subset.insert(doc);
    });
    

    Note: As of MongoDB 2.6, the aggregation framework makes it possible to do this faster; see melan's answer for details.

提交回复
热议问题