-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_query.js
36 lines (29 loc) · 883 Bytes
/
01_query.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const repl = require('repl').repl
const { play } = repl.context
const Rx = require('node-keyboard-rx')()
const mongo = require('..')
module.exports = () => {
const { query, log, compose } = mongo
// to test start mongo on localhost:26000
// > mongod --port 26000
// then run shell
// > mongo --port 26000
// insert docs
// > db.getSiblingDB('test').users.insert({})
const cursor = query({
uri: 'mongodb://localhost:26000',
db: 'test',
collection: 'users',
findQuery: {
name: {
$exists: 1
}
}
})
// tail is Rx Observable of oplog events
cursor
.concatMap(x => Rx.Observable.of(x).delay(500))
.do(log) // log out received data
.flatMap(compose) // transform data into music
.subscribe(play, console.error) // play music
}