MongoDB is a free and open-source cross-platform document orient database program. Unlike classic SQL databases, MongoDB uses BSON (like JSON) to store data. Meteor was designed to use MongoDB for database storage and this topic explains how to implement MongoDB storage into Meteor applications.
Connect Your Local Meteor App to an Alternative Mongo DB
MONGO_URL environment variable before starting your local Meteor app.
Note: don't use
Export a Remote Mongo DB, Import Into a Local Meteor Mongo DB
Helpful when you want to grab a copy of a production database to play around with locally.
mongodump --host some-mongo-host.com:1234 -d DATABASE_NAME -u DATABASE_USER -p DATABASE_PASSWORDThis will create a local
dumpdirectory; within that directory you'll see a directory with your
- With your local meteor app running, from within the
mongorestore --db meteor --drop -h localhost --port 3001 DATABASE_NAME
Get the Mongo URL of Your Local Meteor Mongo DB
While your Meteor app is running locally:
You can start the
mongo shell by running the following command inside your Meteor project:
Please note: Starting the server-side database console only works while Meteor is running the application locally.
After that, you can list all collections by executing the following command via the
You can also run basic MongoDB operations, like querying, inserting, updating and deleting documents.
Documents can be queried by using the
find() method, e.g.:
This will list all documents that have the
name attribute set to
If you want to insert documents in a collection, run:
In case you want to update documents, use the
update() method, for instance:
Executing this command will update a single document by setting the value
John Doe for the field
name (initially the value was
If you want to update all documents that match a specific criteria, set the
multi parameter to
true, for example:
Now, all documents in the collection that had initially the
name attribute set to
Matthias Eckhart have been updated to
Documents can be easily removed by using the
remove() method, for example:
This will remove all documents that match the value specified in the
Running Meteor without MongoDB
MONGO_URL to any arbitrary value except for a database URL and ensure no collections are defined in your Meteor project (including collections defined by Meteor packages) to run Meteor without MongoDB.
Note that without MongoDB, server/client methods alongside any packages related to Meteor's user-account system will be undefined. Ex: