Let's snoop all those data changes, shall we. Spyder reads from the oplog and creates a channel out of that.
Each update is expected to contain and 'update_spec'. That one should contain the organization, app_name, user and timestamp.
{
_id: ObjectId("5eeded5eeded5eeded5eeded"),
update_spec: {
timestamp: ISODate("2015-07-16T14:48:06.098Z"),
app_name: "adminapp",
organization: ObjectId("5eeded5eeded5eeded5eeded"),
user: ObjectId("5eeded5eeded5eeded5eeded")
},
}
Services can register to spyder and filter for a collection within mongo.
spyder.FlyRegistry["actionapp.actions"] = actionapp.Handler
Reading the channel can be done in this way:
func readOplog(settings *config.Config, session *mgo.Session) {
ops := spyder.Tail(
session,
progress(settings),
&spyder.TailOptions{nil, getFilter(settings)},
)
// Tail returns 2 channels - one for events and one for errors
func() {
for {
// loop forever receiving events
fly := <-ops
listener(settings, fly)
}
}()
}
The channel is populated by flies.
type Fly struct {
Id string
Timestamp bson.MongoTimestamp "ts"
HistoryID int64 "h"
MongoVersion int "v"
Operation string "op"
Namespace string "ns"
Object bson.M "o"
Query bson.M "o2"
updateSpec bson.M
}
- close running mongo instance if needed
- restart mongo using right db paths etc using replSet
mongod --port 27017 --dbpath /data/db --replSet rs0
Connect to mongo
mongo
Initiate the replicaset and check for status
rs.initiate()
rs.status()
-
Pull the latest source code for API, Router & CarpetJs.
-
Clone the Spyder repository.