简体   繁体   中英

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.

I have started a mocha test runner with meteor test --driver-package practicalmeteor:mocha . If I try to start a mongo console with meteor mongo I get this error.

mongo: Meteor isn't running a local MongoDB server.

This command only works while Meteor is running your application locally. Start your application first with 'meteor' and then run this command in a new terminal. This error will also occur if you asked Meteor to use a different MongoDB server with $MONGO_URL when you ran your application.

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?

When in 'test-mode', Meteor creates a dummy test-database to avoid overwriting data during testing.

This dB runs on port 3001 by default, but you cannot connect to it using meteor mongo ( you cannot specify the port )

If you have a real mongodb instance installed ( not the meteor built-in one), you can connect using:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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