从提示中获取数组并插入MongoDB数据库

时间:2017-03-03 23:12:38

标签: javascript mongodb meteor

我正在开发一个社交网络类型的网站。我想要一种方法,我可以提示用户,在数组中获取响应,然后一次插入数组。虽然我可以提示我在将数组插入mongodb数据库时遇到问题。这是我的代码:

foo := this|works
bar := "I lost my 'single quotes'"
baz := 'make|will|not|accept|this|with|the|single|quotes'

whatIWant := "A string with its 'single|quoted|regex|alternatives'"

this-almost-works:  #But the single quotes are lost.
        @printf '%s ' "$(whatIWant)"

this-fails-horribly:
        @printf '$(whatIWant)'

将其插入:

/bin/sh: 1: quoted: not found
/bin/sh: 1: /bin/sh: 1: regex: not foundalternatives": not found

blah blah Error 127

1 个答案:

答案 0 :(得分:1)

由于您正在插入并且users已经是一个数组,因此您不需要$push。另外,您无需推送{}对象。

Channels.insert({
  name: channelName,
  created: new Date(), 
  members: users, 
  createdBy: username
});

同时在客户端,跳过arr.join() - 即创建字符串,但您只想传递直接创建的数组。

Meteor.call('addChannel', channelName, arr);