Search code examples
reactive-programming

How to recieve reactive mongo data using Rx 3.1.0v and pymongo python


I'm trying to get observable mongo data using Rx 3.1.0, im trying to implement "Observable.from_" an error appear that "from_" is not recongized as observable method

from pymongo import MongoClient
from rx import Observable

def collect_data(dbname, collection):
clt = MongoClient('localhost', 27017)
db = clt[dbname]
col = db[collection]

colData= col.find().limit(10)
return Observable.from_(colData)
collect_data('test', 'money').subscribe(print(data))

an error appear that "from_" is not recongized as observable method

I'm trying to use rx.of

from pymongo import MongoClient
import rx

def collect_data(dbname, collection):
clt = MongoClient('localhost', 27017)
db = clt[dbname]
col = db[collection]

colData= col.find().limit(10)
return rx.of(colData)
collect_data('test', 'money').subscribe(lambda data: print('{0}'.format(data)))

I get

<pymongo.cursor.Cursor object at 0x000001BF824FE8C8>

Solution

  • instead of

    Observable.from_(colData)

    i should replace with the new statement of RxPY 3.1.0

    rx.from_(colData).pipe( ops.filter(...), ops.distinct(...), ops.take(...), ops.map(...), )