繁体   English   中英

部署应用程序后,流星数据库find()不返回文档

[英]Meteor database find() doesn't return documents when app deployed

我有以下HTML:

<template name="something">
  {{#each biller}}
    <div>write_something</div>
  {{/each}}
</template> 

#each biller的帮助程序如下:

billers = new Mongo.Collection("billers");

Template.something.helpers({
  biller: function(param){
    return billers.find({param:param}) ;
  }
});

部署到localhost时,此方法可以正常工作。 但是,当我使用meteor deploy部署到subdomain.meteor.com ,# #each biller的div #each biller为空-没有内容。 然后,我用return ['a','b'] (某个数组)替换了助手中的billers.find() ),它再次正常工作。 因此,我将问题缩小到以下事实:在部署时billers.find()无法按预期工作,可能无法连接到数据库。 虽然这不起作用,但是在浏览器控制台中,我看到以下消息:
WebSocket connection to 'wss://ddp--3592-biller2.meteor.com/sockjs/969/mty9hj18/websocket' failed: WebSocket is closed before the connection is established. cbd6db56612e463370fc8f0b4c909d896b48d176.js:32 WebSocket connection to 'wss://ddp--5246-biller2.meteor.com/sockjs/849/wr1l0s5w/websocket' failed: WebSocket is closed before the connection is established. 我不知道这个错误信息是否与我面临的问题有关。 有想法该怎么解决这个吗?
更新:
我在辅助程序中添加了一行,如以下注释中所述: if(billers.find().count()==0) console.log("zero") else console.log("not zero")

在localhost上运行时,它给出“非零”,在subdomain.meteor.com上运行时,它显示“零”。 因此,我猜想find()可以正常工作,但它获取零个文档。 为什么会这样呢?

不确定为什么代码在localhost中可以工作,因为要查找的输入应该是String或Object。 这是collection.find文档

我想你的意思是这样写代码

Template.something.helpers({
  biller: function(param){
    return billers.find({param:param});
  }
});

您需要“启动”数据库。 这意味着您将创建所谓的“灯具”。

因此,在您的/ server目录中创建一个名为“ fixtures.js”的文件。 在其中写道:

if (Billers.find().count() === 0)
    Billers.insert({
       "billerName":"Testing"        
    })

也改变

billers = new Mongo.Collection(“ billers”);

Billers = new Mongo.Collection(“ billers”);

大写字母表示miniMongo查询(客户端),小写字母表示mongo查询(服务器端)。

暂无
暂无

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

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