在Meteor Collection中插入多个文档是否与纯mongodb相同? [英] Does inserting multiple documents in a Meteor Collection work the same as pure mongodb?

查看:51
本文介绍了在Meteor Collection中插入多个文档是否与纯mongodb相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我不能以与在Mongodb文档中进行了描述 ...

It seems I can't do a multiple insert in Meteor the same way it is described here in the Mongodb documentation...

在我的js控制台中:

> Test.insert([{name:'hello'},{name:'hello again'}])

返回

  "g3pq8GvWoJiWMcPkC"

我去的时候

Test.find().fetch()

我得到以下信息:

Object
0: Object
name: "hello"
__proto__: Object
1: Object
name: "hello again"
__proto__: Object
_id: "g3pq8GvWoJiWMcPkC"
__proto__: Object

Meteor似乎创建了一个超级文档,其中包含我要插入的两个文档.

It seems Meteor creates a super document encompassing the two I'm trying to insert as separate ones.

有人可以告诉我我在做什么错吗?

Could someone tell me what I'm doing wrong here?

推荐答案

来自Meteor排行榜示例代码,您似乎无法批量插入.您可以使用循环或下划线迭代功能.

From the Meteor leaderboard example code, it looks like you cannot bulk insert. You can either use a loop or underscore iteration function.

使用下划线,

var names = [{name:'hello'},{name:'hello again'}]

_.each(names, function(doc) { 
  Test.insert(doc);
})

这篇关于在Meteor Collection中插入多个文档是否与纯mongodb相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆