【问题标题】:mongoDB doesn't insert in the document's rootmongoDB 不插入文档的根目录
【发布时间】:2013-11-21 13:52:45
【问题描述】:

我在 var 中有一个这样的集合:

var temp = Collection.find({nom: "lol"}).fetch();

我在这里更改_id

Collection2.insert(temp);

在 mongoDB 我有这个:

{
    "0" : {
       _id: "65462984521651" //<- The id I have change
       //Some other data
       //....
      },
    _id : "dvhssdhvflidsfjhv"
}

如何将文档插入根目录而不是“0”? 谢谢:)

【问题讨论】:

    标签: javascript mongodb insert meteor


    【解决方案1】:

    cursor.fetch method 总是返回一个数组。 collection.insert method 总是需要一个文档,这不像本地 MongoDB JS 驱动程序,它将接受批量插入。

    Does inserting multiple documents in a Meteor Collection work the same as pure mongodb?已经介绍了如何插入多个文档。

    考虑以下(而不是Collection2.insert(temp)):

    temp.forEach(function(doc) {
        Collection2.insert(doc);
    });
    

    还可以考虑将变量命名为不同于temp ...temp 什么?临时总职位?临时消息?临时用户名? Collection 和 Collection2 也是如此。再说一次,这些名称可能只是针对这个特定的 SO 问题;所以如果是这种情况,请忽略此注释!

    【讨论】:

      猜你喜欢
      • 2016-08-11
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 2021-06-07
      • 1970-01-01
      • 2012-08-29
      相关资源
      最近更新 更多