Meteor and Mongo in Windows 8 - mongodb

I started Meteor tutorial and I was able to run a few basic items said in the first 2 steps in the 3 step they ask to add this code
Tasks = new Mongo.Collection("tasks");
but when I try to run meteor in the app folder I got (tried it by running Meteor alone and Meteor + Meteor mongo in separate shell of same folder)
ReferenceError: Mongo is not defined
What am I missing here how to make the connection working ?

haha my mistake I think the tutorial given
https://www.meteor.com/try/3
is old or something the issue is sorted when you use
Tasks = new Meteor.Collecion
instead of
new Mongo.Collection

Related

How to persist mongodb when deploying with meteor?

When I meteor deploy my app, it seems to create an entirely new mongodb instance. I'd like to be able to deploy with the current mongodb have locally.
Same goes the other way -- I'd like to be able to download the mongodb back to my localhost after it has been deployed.
For clarification, I'd really like to know the follow:
1) how to deploy with a fresh mongodb
2) how to deploy to an existing deployed app without overwriting the old mongodb
3) how to download/sync mongodb locally with the existing deployed app
4) how to make local backups of mongodb
You can perform a mongo dump using meteor mongo to export your local database and deploy your app using Meteor Up which should also allow you to automate the database import and deployment process.
"Meteor Up (mup for short) is a command line tool that allows you to deploy any meteor app into your own server."
You can stop the mongodb service and start a mongod instance in a separate terminal, by just typing mongod. This will let you monitor what's happening on the mongodb instance that you just started.
Open another terminal and do export MONGO_URL=mongodb://localhost:27017/nameOfDBgoesHere
This will create a new DB named "nameOfDBgoesHere" and it won't overwrite what you currently have, unless you name it with the same name.
After that just start meteor by typing meteor in your program's folder. In the mongod terminal that you opened you should see some connections opening.
By default mongodb creates it's DB files in /data/db. If you have another meteor app and follow the same steps in another terminal, while keeping the name of the DB you specified in the MONGO_URL you will just connect to it from that app - without overwriting anything.
As for the syncing with a deployed app and the local backups of mongo - it seems like something that the mongodb website covers, but maybe someone can chime in here. Not sure if there is a meteor specific, easy way of doing this.

Meteor without mongo

With 0.6.5 release it is possible to develop non web apps with meteor.
I rebuild it from scratch for ARM processor but I don't want DB support at all. (Mongo is a processor killer, has to high footprint and I simply don't need it)
ARM should work as DDP client only, with this in mind I build it manually without mongo.
And tried to build simplest app possible
only 1 package at start (all standard packages removed)
meteor
and one file in server folder
main = function(argv){
return "DAEMON"
}
Meteor.setInterval(function(){
console.log("HellOnWorld");
},1000);
On machine with full meteor install it works as expected
but without mongo installed I got errors
Unexpected mongo exit code 127. Restarting.
Unexpected mongo exit code 127. Restarting.
Initializing mongo database... this may take a moment.
Unexpected mongo exit code 127. Restarting.
Can't start mongod
Obviously I don't have and want mongo.
Is there any way to start meteor without waiting for mongo db ?
Meteor team plans to support other db's so it must be implemented sooner or later.
UPDATE
For newer versions of Meteor you need to remove the mongo package. The mongo package is embedded in the meteor-platform package. So you need to remove that and add all the rest back (from https://github.com/meteor/meteor/tree/devel/packages/meteor-platform):
meteor remove meteor-platform
meteor add meteor webapp logging tracker session ddp blaze spacebars templating check underscore jquery random ejson templating check underscore jquery random ejson
Then your app won't use Mongo anymore :).
In dev mode you can get rid of mongo by setting the MONGO_URL environment variable to something else and start meteor. For example: MONGO_URL=mongodb://nowhere meteor
Turns out that if you just set any MONGO_URL environment variable before running meteor, it won't start its local MongoDB! Fantastic for testing packages that don't depend on Mongo.
Before:
$ meteor test-packages ./
Testing fortawesome:fontawesome-compat...
[[[[[ Tests ]]]]]
=> Started proxy.
=> Started MongoDB.
=> Started your app.
=> App running at: http://localhost:3000/
After
$ MONGO_URL=mongodb://mysql.com meteor test-packages ./ # haha
Testing fortawesome:fontawesome-compat...
[[[[[ Tests ]]]]]
=> Started proxy.
=> Started your app.
=> App running at: http://localhost:3000/
Look ma, no Mongo!
I have confirmed that no mongo process is started, and no .meteor/local/db folder is created.
In Meteor 0.6.5, you can embed TingoDb, a Node.js implementation of the MongoDB API, with your Meteor bundle instead:
1) Go to the programs/server directory in your bundle and do npm install tingodb to add TingoDb to your bundle.
2) Near the top of programs/server/packages/mongo-livedata.js, with all of the other Npm.require statements, add the following line
var Db = Npm.require('tingodb')().Db;
3) In that same file (programs/server/packages/mongo-livedata.js) replace the following code block
MongoDB.connect(url, options, function(err, db) {
if (err)
throw err;
self.db = db;
Fiber(function () {
// drain queue of pending callbacks
_.each(self._connectCallbacks, function (c) {
c(db);
});
}).run();
});
with this code:
var db = new Db('path/to/your/db/directory', {});
self.db = db;
Fiber(function () {
_.each(self._connectCallbacks, function (c) {
c(db);
});
}).run();
The path/to/your/db/directory can be anywhere, but is relative to the programs/server directory in your bundle by default.
4) To run your Meteor bundle, it wants you to export an environment variable called MONGO_URL. You could dive in to the code and remove the checks for this, but since it's never used you can just as easily export a fake MONGO_URL, like the one in your bundle's README file:
export MONGO_URL='mongodb://user:password#host:port/databasename'
5) From your bundle's base directory run node main.js.
Caveat emptor: obviously you're messing around with Meteor internals here, and this will almost assuredly break with future versions.
Meteor 1.2.1 - Just set
MONGO_URL=none
for an environment variable. (none isn't a keyword, anything invalid appears to prevent mongo from starting)
As a weird possibility, make a mock mongo server on the right port, and set your environnmental variable to access it. I'd bet you only need a few handshake routines be implemented and no more traffic after that. Beyond my capability, but it does have the advantage of not needing to adopt to code changes as things shift.
The listed answers are not working with the Meteor 1.x.
Following is my way to run meteor without mongodb and doesn't need modify anything(neither source code nor packages configuration) in meteor.
git clone https://github.com/solderzzc/mongodb-fs
cd mongodb-fs && npm install && node samples/test-server.js
you will see following console log if everything goes well
meteor create --example leaderboard && cd leaderboard
MONGO_URL=mongodb://localhost:27027/fakedb meteor
Add point to the player, and check with the mongo command line:
mongo localhost:27027/fakedb

Meteor does not connect to MongoDB

I'm trying to connect Meteor to an existing MongoDB. I can't duplicate the database or change its name, because is used by other app.
I know I have to set a MONGO_URL environment var to connect with it. However, after I set it, Meteor is not connecting to the especiefied MongoDB database. I tried doing a .find() but it does not return any docs. An .insert() from the web console shows the info in the page, but it doesn't get inserted in 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 Meteor version release is 0.6.4.1, and the MongoDB version is 2.4.1.
UPDATE: July 28
After running meteor with meteor run, I opened a new console window within project directory to run a meteor mongo console. However, after running meteor mongo I received the following:
mongo: Meteor isn't running.
This command only works while Meteor is running your application
locally. Start your application first.
As you know, because you posted the issue, this is a bug in meteor.
My workaround was to connect to my mongodb with the standard mongo client. You can find what port your db is running on by looking at the file yourapp/.meteor/db/METEOR-PORT and then just run mongo localhost:[put that port number here] .
Are you sure the problem is that Meteor doesn't connect to the database? You have several pieces here that have to work together. I don't see anything obviously wrong, but I would simplify the code to verify the problem is where you think it is.
For example, try adding console.log(Posts.find()) to Meteor.startup on the server.
I am assuming you run Meteor on Linux or Mac. If this is not the case, the code might not work.
the most obvious reason is that the mongo database does not contain any posts documents. What is the output of:
$ mongo
> use autana_dev
> db.posts.find({}).count()
If the output is not null or 0 you might need to connect with a username and password.
export MONGO_URL="mongodb://user:password#localhost:27017/autana_dev
if this does not help, I'd try adding a bit of logging to find out if posts are not 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 condition if( postsHanlde.ready() ) ensures you do not try to show the posts before they have arrived.
If you have documents in your mongodb but nothing gets selected in Meteor, maybe your mongodb is not working correctly.
It is fairly easy to check that by replacing the mongodb with an online solution. Create a free account on mongolab and change your MONGO_URL to the one given by the mongolab console. Insert some posts there and test again.
If you still do not get any documents, then ...
That is all I can think of from your input. Hope it helped.
First, run mongo in one shell's windows
Then simply run "meteor mongo" in another shell's windows while the fist is still running !
On my mac, in the "leaderboard exemple", here is how i've done :
"meteor run leaderboard "
"cd .meteor/leaderboard;meteor mongo "

How is MongoDb installed by Meteor?

I'm new to both Meteor.js and MongoDB and after installing Meteor in the official way described I wonder how to connect to my MongoDB.
MongoDB was installed by Meteor during the installation and everything works fine but now I would like to have a look into it with another tool (like RazorSQL) to see what's in there.
But the standard connection parameters (localhost:27017) doesn't work, what can I do? Login? Password?
Update: February 2014 - Meteor 0.7.1 - The meteor port has been shifted to 3001 instead of 3002. So instead of adding two to the port meteor runs on, you add 1 instead.
MongoDB's database is installed in the meteor package containing your files in a hidden folder called .meteor. To access it from a remote tool simply add 2 to whatever your web server port is while meteor is running. It will be stored in the meteor database
e.g
http://localhost:3000 would have its mongodb server running at mongodb://localhost:3002/meteor there is no username/password on this instance if you ran it with meteor or meteor run
To get the Meteor Mongo url and port, first run your Meteor app using meteor run then run meteor mongo in a different terminal tab. You should see an output like this
[meteor-app] meteor mongo
MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:3001/meteor
this means that your Meteor Mongo is running at 127.0.0.1:3001.
If you are running your Meteor app with meteor run then you neither need username/password nor authentication configuration just make sure that you set your default database name as meteor

When using a separate MongoDB with meteor, meteor reset stopped working

I have my MONGO_URL set to mongodb://localhost:27017/meteor and have the MongoDB run as a service.
When running my project it seems OK to store data to the separate MongoDB until I tried to run meteor reset.
My assumption is it tried to remove its default database. The error complained that myproject.meteor\local is not empty and pointed to fs.js:456 which goes to files.js:256 (rm_recursive) and so on.
any idea what and how I can fix this?
$ meteor reset only resets the bundled MongoDB. It won't reset an external Mongo database.
(That's something we should explain better in the documentation.)
In your case, try connecting to the Mongo database directly (with the mongo command line shell) and running > db.dropDatabase()