search

Home  >  Q&A  >  body text

如何实现将 MongoDB中group分组后的结果,再存入到mongo数据库中????

先通过mongo中的聚合函数:group()后返回的是DBObject 对象,我想将其存入另一个集合中,怎么办???

过去多啦不再A梦过去多啦不再A梦2796 days ago792

reply all(2)I'll reply

  • 为情所困

    为情所困2017-04-24 16:01:32

    Later, I figured it out myself, just put it directly into a document and insert it into the collection. .

    reply
    0
  • 習慣沉默

    習慣沉默2017-04-24 16:01:32

    collection.aggregate([
        {
            '$match': {}
        },
        {
            '$group': {}
        }
    ], {
        out: 'OtherCollection'
    })
    

    Requires MongoDB 2.6+
    And every time you go out, the previous data will be erased
    If you don’t want it to be erased, insert the structures into a new collection in batches

    reply
    0
  • Cancelreply