I'm following the telescope tutorial.
In this tutorial I'm told to insert a new post by opening the Mongo console.
$ meteor mongo
How can I:
$ meteor mongo (somehow connect to my remote DB to use the meteor commands in terminal
So that I can:
$ db.collectionname.insert({ stuff });
Or does this have nothing to do with "Meteor" in this case and I just use a Mongo shell outside of Meteor? The collection that I created in "/client/collections/collection.js" is this simply for telling Meteor which collection to push as a subset to the client?
I'd like to use the same DB ( remotely hosted with MongoHQ) for my localhost development, and my actual live dev.mysite.com so when I deploy to this dev site, anything I've done in the DB is also there and ready to go.
Assuming you had a username of username
, a password of PASSWORD
, a database named test
, and a hostname of hatch.mongohq.com
:
$ mongo hatch.mongohq.com:27017/test -u username -p PASSWORD
$ MONGO_URL="mongodb://username:[email protected]:27017/test" meteor
You should define your Meteor collections outside of the client
directory so they can be used on both the client and the server. See this for more details.
You will find that connecting to a remote database is much slower than connecting locally, so it's generally not recommended for development.
Meteor creates a dev database for you when it starts. This also affords you the very helpful commands: meteor reset
and meteor mongo
, to reset, and connect to said database.
Create a file on the server for initialization - e.g. server/initialize.js
. When the server starts you can add users or other documents which do not yet exist. For example:
Meteor.startup(function() {
if (Meteor.users.find().count() === 0) {
Accounts.createUser({
username: 'jsmith',
password: 'password',
profile: {
firstName: 'John',
lastName: 'Smith'
}
});
}
});