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
Collection name. Pass
null for a local (client-only) collection.Server connection. Uses default if not specified. Pass
null for local collections.ID generation method:
'STRING' for random strings or 'MONGO' for MongoDB ObjectIDsFunction to transform documents before returning from queries
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
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.