Skip to main content
The mongo package provides Meteor’s full-stack database driver for MongoDB, enabling real-time data synchronization between client and server through LiveQuery.

Installation

The mongo package is included by default in Meteor applications.

Overview

The mongo package provides:
  • Mongo.Collection - Unified API for client and server database access
  • LiveQuery - Real-time updates via MongoDB oplog tailing
  • Minimongo - Client-side MongoDB implementation
  • Cursors - Reactive database queries
  • Oplog Observer - Efficient change detection
  • DDP Integration - Automatic data synchronization

Package Information

  • Version: 2.2.0
  • Summary: Adaptor for using MongoDB and Minimongo over DDP
  • Dependencies: minimongo, ddp, tracker, npm-mongo
  • NPM packages: MongoDB Node.js driver

Creating Collections

Basic Collection

Collection with Options

name
string
required
Collection name. Pass null for a local (client-only) collection.
options.connection
DDP.Connection
Server connection. Uses default if not specified. Pass null for local collections.
options.idGeneration
string
default:"STRING"
ID generation method: 'STRING' for random strings or 'MONGO' for MongoDB ObjectIDs
options.transform
function
Function to transform documents before returning from queries
options.defineMutationMethods
boolean
default:"true"
Whether to define insert/update/remove methods for client use

Local Collections

Client-only collections (not synchronized):

CRUD Operations

Insert

Find

Update

Upsert

Remove

Queries and Selectors

Query Operators

Query Options

Cursors

Reactive Cursors

Observe Changes

Watch for real-time changes:

Observe Field Changes

Lower-level observer for efficiency:

Indexes

Security with Allow/Deny

By default, client-side database operations are not allowed. Use allow/deny rules or remove insecure package and use Methods.

Allow Rules

Deny Rules

Using Methods Instead

Raw MongoDB Access

Raw Collection

Raw Database

Direct npm Module Access

MongoDB ObjectID

Transactions (Server)

LiveQuery and Oplog

Meteor uses MongoDB’s oplog (replication log) for efficient real-time updates. This is called LiveQuery.

Oplog Configuration

Disable Oplog

Polling Observer

When oplog is unavailable, Meteor falls back to polling:

Collection Extensions

Performance Tips

Create appropriate indexes - Index fields used in queries and sorts
Use projections - Only fetch fields you need
Limit results - Use limit and skip for pagination
Avoid observe on large datasets - Use publications with observeChanges instead

Source Code