meteor MongoDB Getting Started


Example

You can start the mongo shell by running the following command inside your Meteor project:

meteor mongo

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 mongo shell:

show collections

You can also run basic MongoDB operations, like querying, inserting, updating and deleting documents.


Query Documents

Documents can be queried by using the find() method, e.g.:

db.collection.find({name: 'Matthias Eckhart'});

This will list all documents that have the name attribute set to Matthias Eckhart.

Inserting Documents

If you want to insert documents in a collection, run:

db.collection.insert({name: 'Matthias Eckhart'});

Updating Documents

In case you want to update documents, use the update() method, for instance:

db.collection.update({name: 'Matthias Eckhart'}, {$set: {name: 'John Doe'}});

Executing this command will update a single document by setting the value John Doe for the field name (initially the value was Matthias Eckhart).

If you want to update all documents that match a specific criteria, set the multi parameter to true, for example:

db.collection.update({name: 'Matthias Eckhart'}, {$set: {name: 'John Doe'}}, {multi: true});

Now, all documents in the collection that had initially the name attribute set to Matthias Eckhart have been updated to John Doe.

Deleting Documents

Documents can be easily removed by using the remove() method, for example:

db.collection.remove({name: 'Matthias Eckhart'});

This will remove all documents that match the value specified in the name field.