简体   繁体   English

运行流星测试时,如何连接到mongo数据库?

[英]When running meteor tests, how can I connect to the mongo db?

I have a new meteor application, and have a few tests that inserts data into a mongo collection, but no UI for that yet. 我有一个新的流星应用程序,并且进行了一些测试,将数据插入到mongo集合中,但是还没有UI。

I have started a mocha test runner with meteor test --driver-package practicalmeteor:mocha . 我已经用meteor test --driver-package practicalmeteor:mocha启动了一个摩卡测试meteor test --driver-package practicalmeteor:mocha If I try to start a mongo console with meteor mongo I get this error. 如果我尝试使用meteor mongo启动mongo控制台, meteor mongo此错误。

mongo: Meteor isn't running a local MongoDB server. mongo:Meteor没有运行本地MongoDB服务器。

This command only works while Meteor is running your application locally. 该命令仅在Meteor在本地运行应用程序时有效。 Start your application first with 'meteor' and then run this command in a new terminal. 首先使用“ meteor”启动您的应用程序,然后在新终端中运行此命令。 This error will also occur if you asked Meteor to use a different MongoDB server with $MONGO_URL when you ran your application. 如果您在运行应用程序时要求Meteor将其他MongoDB服务器与$ MONGO_URL一起使用,也会发生此错误。

If you're trying to connect to the database of an app you deployed with 'meteor deploy', specify your site's name as an argument to this command. 如果您尝试连接到使用“流星部署”部署的应用程序的数据库,请指定站点名称作为此命令的参数。

How can I connect to the mongo to see which documents have been created by the tests? 如何连接到mongo以查看测试已创建了哪些文档?

When in 'test-mode', Meteor creates a dummy test-database to avoid overwriting data during testing. 当处于“测试模式”时,Meteor将创建一个虚拟测试数据库,以避免在测试期间覆盖数据。

This dB runs on port 3001 by default, but you cannot connect to it using meteor mongo ( you cannot specify the port ) 默认情况下,此dB在端口3001上运行,但是您不能使用meteor mongo连接到它(您不能指定端口)

If you have a real mongodb instance installed ( not the meteor built-in one), you can connect using: 如果您安装了真正的mongodb实例(而不是内置的流星),则可以使用以下方法进行连接:

mongo meteor --port 3001

It looks like your environment variable problem. 看来您的环境变量问题。

export MONGO_URL=''
meteor mongo

You can also try if there is some permission issues : 您还可以尝试是否存在一些权限问题:

sudo meteor mongo

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

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