Meteor does not connect to MongoDB

I am trying to connect Meteor to an existing MongoDB. I cannot duplicate a database or change its name because it is used by another application.

I know. I need to install the MONGO_URL var environment to communicate with it. However, after I installed it, Meteor does not connect to the MongoDB database. I tried to do .find() , but it does not return any documents. .insert() from the web console shows the information on the page, but it is not inserted into the database. Here are the codes:

 $ echo $MONGO_URL mongodb://localhost:27017/autana_dev 

./Lib/models.js

 Posts = new Meteor.Collection('posts'); 

./server/app.js

 Meteor.publish('posts', function() { return Posts.find(); }); 

./client/app.js

 Meteor.subscribe('posts'); Template.main.posts = function() { return Posts.find(); }; 

Any idea? Anyone? My release of the Meteor version is 0.6.4.1, and the MongoDB version is 2.4.1.

UPDATE: July 28th After starting meteor using meteor run I opened a new console window in the project directory to start the meteor mongo console. However, after running meteor mongo I got the following:

 mongo: Meteor isn't running. This command only works while Meteor is running your application locally. Start your application first. 
+6
source share
4 answers

As you know, because you posted the issue , this is a mistake in the meteor.

My workaround was to connect to my mongodba with a standard mango client. You can find out which port your db is running on by looking at yourapp/.meteor/db/METEOR-PORT , and then just run mongo localhost:[put that port number here] .

+3
source

Are you sure the problem is that Meteor is not connecting to the database? You have a few pieces here that should work together. I don't see anything clearly wrong, but I would simplify the code to check that the problem is where you think.

For example, try adding console.log (Posts.find ()) to Meteor.startup on the server.

0
source

I assume that you are running Meteor on Linux or Mac. If this is not the case, the code may not work.

The most obvious reason is that the mongo database does not contain any posts documents. What is the result:

 $ mongo > use autana_dev > db.posts.find({}).count() 

If the output is not null or 0 , you may need to connect with a username and password.

 export MONGO_URL="mongodb://user: password@localhost :27017/autana_dev 

If this does not help, I would try adding a bit of logging to see if messages were sent or not received:

 Meteor.publish('posts', function() { console.log("returning " + Posts.find({}).count() + " posts"); return Posts.find(); }); 

and if the number is greater than 0 on the client

 var postsHandle = Meteor.subscribe('posts'); Template.main.posts = function() { if( postsHanlde.ready() ){ console.log("I have " + Posts.find({}).count() + " posts on the client"); return Posts.find(); } }; 

the if( postsHanlde.ready() ) condition if( postsHanlde.ready() ) ensures that you don’t try to show posts until they arrive.

If you have documents in your mongodb but nothing is selected in Meteor, your mongodb may not work correctly.

Easy enough to check by replacing mongodb with an online solution. Create a free account on mongolab and change your MONGO_URL to the one set by the mongolab console. Insert some messages there and check again.

If you still do not have documents, then ...

That’s all I can come up with with your input. Hope this helps.

0
source

Start mongo first in one shell window

Then just run “meteor mongo” in the other shell windows while the fist is still working! On my mac, in the “Leaders Example”, here is how I did it:

  • "meteorite driven list"
  • "cd. meteor / leaderboard, meteor mongo"
0
source

Source: https://habr.com/ru/post/950373/


All Articles