Skip to content

Instantly share code, notes, and snippets.

@gaurav-singh1990
Last active January 1, 2017 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaurav-singh1990/759c22b058a6305c11f3023c526b40b2 to your computer and use it in GitHub Desktop.
Save gaurav-singh1990/759c22b058a6305c11f3023c526b40b2 to your computer and use it in GitHub Desktop.
require 'rx'
require 'mongo'
aggregate_query = [
{
'$group' => {
'_id' => "$_id",
'count' => {
'$sum' => 1
}
}
},
{
'$limit' => 5
}
]
context = {}
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'test')
collection = client['test']
find_patient_subject = Rx::Observable.start(
lambda {
collection.find({}, { projection: {name:1}}).limit(5)
},
context,
Rx::DefaultScheduler.instance
)
count_patient_subject = Rx::Observable.start(
lambda {
collection.aggregate(aggregate_query)
},
context,
Rx::DefaultScheduler.instance
)
count_subscription = count_patient_subject.subscribe(
lambda {|x| x.each do |m| p m end},
lambda {|e| p e},
lambda {p 'aggregate completed'}
)
patient_subscription = find_patient_subject.subscribe(
lambda {|x| x.each do |m| p m end},
lambda {|e| p e},
lambda {p 'find completed'}
)
sleep(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment