Firebase Python'Reference'对象没有属性'limit_to_last'

时间:2018-03-06 10:50:30

标签: python firebase firebase-realtime-database firebase-admin

import firebase_admin
enter code here`from firebase_admin import credentials
from firebase_admin import db

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
cred = credentials.Certificate('path/to/serviceAccountKey.json')
firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://databaseName.firebaseio.com'
})
ref = db.reference('dinosaurs')
snapshot = ref.order_by_child('height').limit_to_last(2).get()
for key in snapshot:
    print (key)

我已按照this page上的说明操作,但我收到此错误:

'Reference' object has no attribute 'limit_to_last'

我确保正确安装Python Admin SDK。以前有人遇到过这个问题吗?

1 个答案:

答案 0 :(得分:3)

我已经明白了!

我不需要使用order_by_child(),而是需要调用order_by_key()即使我没有按任何键进行排序。然后我可以致电limit_to_last()limit_to_first()

谢谢你们!