简体   繁体   English

当startup.js加载以使用Mongo时流星崩溃

[英]meteor crashes when startup.js loads to use Mongo

I am creating a Mongo database for meteor. 我正在为流星创建一个Mongo数据库。 I create a startup.js file, so meteor can load the files. 我创建了一个startup.js文件,以便流星可以加载这些文件。 as soon as meteor starts it crashes. 流星一开始它就崩溃了。 can anyone help me pls? 有人可以帮我吗?

html file html文件

<body>
  <div class="container">
    {{> images}}
  </div>
</body>
<template name="images">
  <div class="row">
    {{#each images}}
    <div class="col-xs-12 col-md-3">
      <div class="thumbnail">
        <img class="js-image" src="{{img_src}}" alt="{{img_alt}}" />
      </div>
    </div>
    {{/each}}
  </div>
</template>

startup.js file startup.js文件

if (Meteor.if(Meteor.isServer) {
    Meteor.startup(function() {
        if (Images.find().count() == 0) {
          Images.insert({
              img_src: "laptops.jpg",
              img_alt: "some laptops on a table"
            }
          })
      }
    });
})

image_share.js image_share.js

Images = new Mongo.Collection("images");
if (Meteor.isClient) {
  var img_data = [{
    img_src: "laptops.jpg",
    img_alt: "some laptops on a table"
  }, {
    img_src: "bass.jpg",
    img_alt: "a bass player"
  }, ];
  Template.images.helpers({
    images: img_data
  });
  Template.images.events({
    'click .js-image': function(event) {
      $(event.target).css("width", "50px");
    }
  });
}

error log 错误日志

W20160802-22:15:47.535(3)? (STDERR) (function(Npm,Assets){(function(){if (Meteor.if(Meteor.isServer){
W20160802-22:15:47.535(3)? (STDERR)                                                                 ^
W20160802-22:15:47.535(3)? (STDERR) SyntaxError: Unexpected token {
W20160802-22:15:47.535(3)? (STDERR)     at /data/coursera/meteor.js/week_1/fotini_test/.meteor/local/build/programs/server/boot.js:278:30
W20160802-22:15:47.535(3)? (STDERR)     at Array.forEach (native)
W20160802-22:15:47.535(3)? (STDERR)     at Function._.each._.forEach (/home/fotini/.meteor/packages/meteor-tool/.1.3.2_4.s16sw2++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20160802-22:15:47.535(3)? (STDERR)     at /data/coursera/meteor.js/week_1/fotini_test/.meteor/local/build/programs/server/boot.js:133:5
=> Exited with code: 8

` `

if (Meteor.if(Meteor.isServer)) {
    Meteor.startup(function() {
        if (Images.find().count() == 0) {
            Images.insert({
                img_src: "laptops.jpg",
                img_alt: "some laptops on a table"
            });
        }
    });
}

You forgot one closing ")" and some others was wrong. 您忘记了一个结尾的“)”,而另一些则是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM