Bertie Bravage
Bertie Bravage

Reputation: 11

Problem getting data from a Rethinkdb table in a specific order

The command "rdb.table('newnmeadata').orderBy('nos')" works fine in the RethinkDB data explorer. 'Nos' is the primary key. There are no problems with getting data (for a socket feed) using ".with_fields" but the RethinkDB serves the data in any old order. I have tried many many iterations of the below but am now stumped?

import rethinkdb as r
rdb = r.RethinkDB()
rdb.connect('localhost', 28015).repl()

while True:

    cursor = rdb.table('newnmeadata').orderBy('nos').run()
    for document in cursor:

        msg = (str(document)[10:-13])
        print(msg)

Produces the following error:

Python 3.8.1 (C:/Program Files (x86)/Python/python.exe) %Run datastream.py Traceback (most recent call last): File "C:\Program Files (x86)\Python\MyPy\datastream.py", line 7, in cursor = rdb.table('newnmeadata').orderBy('nos').run() AttributeError: 'Table' object has no attribute 'orderBy'

Upvotes: 0

Views: 304

Answers (2)

Regimantas Baublys
Regimantas Baublys

Reputation: 11

Thanks order_by worked in python :) My Command:

QueryData = r.db('myDB').table('Posts').order_by(r.desc('Data_Time')).run()

works Well Thanks again :)

Upvotes: 1

inf581
inf581

Reputation: 642

It should be order_by for python rethinkdb driver (and orderBy is for javascript). Like this:

cursor = rdb.table('newnmeadata').order_by('nos').run()

Upvotes: 0

Related Questions