【问题标题】:Meteor - difference Client and Server side when accessing remote databaseMeteor - 访问远程数据库时的差异客户端和服务器端
【发布时间】:2016-08-14 06:22:49
【问题描述】:

嗨 Meteor 新手在这里。

在为应用程序制作原型时,我在访问应用程序客户端的远程数据库时遇到问题。更具体地说,我运行流星MONGO_URL="mongodb://__id__:__pwd__@__address__.mlab.com:21010/meteor" meteor

并在公用文件夹中包含以下内容:

Collection = new Mongo.Collection("collection"); console.log(Collection.find().count());

在流星外壳中产生正确的数字,在我的浏览器中产生 0。现在我已经看到here 原因可能是

客户端启动和数据发布之间的延迟

但是,当我在浏览器控制台中尝试 console.log(Collection.find().count()) 时,我得到相同的 0。

为了记录,我没有动过autopublishinsecure

很乐意在这里提供任何建议!

【问题讨论】:

  • 如果您启用了自动发布,那在浏览器控制台中应该可以正常工作。 “服务器控制台”是指“meteor shell”,而不是 mongo shell,对吧?
  • 确实很奇怪。对不起,我的意思是流星壳。我还尝试使用相同的方法连接到本地 mongo 数据库,但遗憾的是结果相同。
  • 如果你正在使用另一个 Meteor 应用程序的数据库,你可以使用DDP.connect

标签: meteor minimongo


【解决方案1】:

您可以像这样创建一个 bash 文件。如果您没有任何 setting.json 文件,请将其从最后一行删除。

#!/bin/bash
: # This shell script runs on both Windows CMD and Bash. The system-specific sections are marked by
: # comments, and share the final invocation of meteor

:<<"::CMDLITERAL"

@ECHO OFF
REM This is the CMD section
ECHO Running in CMD mode
SET export MONGO_URL= mongodb://__id__:__pwd__@__address__.mlab.com:21010/meteor
SET DEV_ENV=development
GOTO :COMMON
::CMDLITERAL

# This is the Bash section
echo Running in Bash mode
export MONGO_URL=mongodb://__id__:__pwd__@__address__.mlab.com:21010/meteor
export DEV_ENV="development"


:<<"::CMDLABEL"
:COMMON
::CMDLABEL

meteor run --settings settings.json --port 4000

您也可以直接使用注释运行 在 liunx 中

export MONGO_URL=mongodb://__id__:__pwd__@__address__.mlab.com:21010/meteor
meteor

在窗口中

SET export MONGO_URL= mongodb://__id__:__pwd__@__address__.mlab.com:21010/meteor
meteor

根据您当前的问题,您在设置 mongo url 时缺少 SET 或 export。

【讨论】:

    猜你喜欢
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 2016-05-12
    • 1970-01-01
    相关资源
    最近更新 更多