mongo-go-examples

command module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2019 License: MIT Imports: 8 Imported by: 0

README

MongoDB mongo-go-driver and Change Streams Examples

A MongoDB Change Streams implementation using mongodb-go-driver.

mongo-go-driver Examples

Examples can be found at examples.

  • Aggregate
    • $group
    • $redact
    • $filter
    • $lookup
    • $elemMatch
  • Change Streams
  • CRUD
  • RunCommand
  • Transactions

Change Streams Demo

Set up a replica set

mkdir -p data/db
rm -rf data/db/*
mongod --port 30097 --dbpath data/db --logpath data/mongod.log --fork --wiredTigerCacheSizeGB .5  --replSet replset
mongo --quiet mongodb://localhost:30097/admin --eval 'rs.initiate()'
mongo --quiet mongodb://localhost:30097/argos?replicaSet=replset --eval 'db.oplogs.insert({"_id": "30097", "scores": [100]})'
Case 1: Watch All Changes
argos "mongodb://localhost:30097/?replicaSet=replset"
Case 2: Watch Changes From a Database
argos "mongodb://localhost:30097/argos?replicaSet=replset"
Case 3: Watch Changes From a Collection
argos --collection oplogs "mongodb://localhost:30097/argos?replicaSet=replset"
Case 4: Watch Changes From a Collection With a Pipeline
argos --collection --pipeline '[{"$match": {"operationType": "update"}}]' \
  "mongodb://localhost:30097/argos?replicaSet=replset"
Stream POC

It would be nice mongo-go-drive can do stream. See POC for an example.

client.Database(db).Collection(collection).Find(filter).Project(project).Sort(sort).Decode(&docs)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL