如何在Meteor上下文中运行脚本?

如何在Meteor上下文中运行脚本?,meteor,Meteor,这有许多应用程序,但我当前的应用程序正在从Cakefile将测试数据加载到数据库中。当我使用mongodb驱动程序创建文档时,它会添加一个对象id(“527d9761ae5c03ce1c000001”)的\u id,而不是像Meteor.Collection.insert自动添加的字符串“he3KMaEwsX457ejPW”。我希望能够在Meteor上下文中运行Cakefile,这样我就可以简单地调用CollectionName.insert,而不是使用mongodb驱动程序。我是这样做的: 卡

这有许多应用程序,但我当前的应用程序正在从Cakefile将测试数据加载到数据库中。当我使用mongodb驱动程序创建文档时,它会添加一个
对象id(“527d9761ae5c03ce1c000001”)
\u id
,而不是像
Meteor.Collection.insert
自动添加的
字符串“he3KMaEwsX457ejPW”
。我希望能够在Meteor上下文中运行Cakefile,这样我就可以简单地调用
CollectionName.insert
,而不是使用mongodb驱动程序。

我是这样做的:

卡基锉 现在,当我运行
cake start
时,
METEOR\u ENV
变量将默认为
'development'
。您可以在此处使用所需的任何字符串运行start,例如:

cake -e production start
server/initialize.coffee 在本例中,服务器启动后,它会查看我们所处的环境。如果是
“生产”
,请退出而不初始化数据库。如果环境是“
development”
,则创建一个交替函数名和集合名的数组。然后,对于每一对,仅当集合为空时才调用该函数。在这种情况下,您需要在别处定义
insertuser
insertGroups

我喜欢这个设置,因为它会在每次流星重置后自动填充我的数据库

cake -e production start
Meteor.startup ->
  environment = process.env.METEOR_ENV ? 'production'
  return if environment is 'production'

  insertCollections = []

  if environment is 'development'
    insertCollections = [
      insertUsers, Meteor.users
      insertGroups, Groups
    ]

  for insert, index in insertCollections by 2
    collection = insertCollections[index + 1]
    insert() if collection.find().count() is 0