我将数据存储在Firebase存储中.
Comment具有属性的对象timestamp.当我将数据从设备推送到Firebase时,我timestamp使用currentTime 填充并存储在long数据类型中.
当我检索数据时,firebaseRef.orderByChild("timestamp").limitToLast(15)结果不是按照我的预期排序.
我甚至玩过规则而没有结果:
{
"rules": {
".read": true,
".write": true,
".indexOn": "streetrate",
"streetrate": {
".indexOn": ".value"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试图储存timestamp在String数据类型,同样的问题.
我正在使用 Ionic 上的 Firestore 编写一个包含按时间顺序排列的用户帖子(最新帖子在顶部)的个人资料页面,方法是将orderBy () 设置为“时间戳”降序。当用户到达底部时,我使用 Ionic 的无限加载来加载更多帖子,但结果是 Firestore 一遍又一遍地加载完全相同的帖子。请帮忙!
你好!
抱歉,如果这是一个初学者问题,但我已经为此思考了几个小时,但无济于事。按升序排列时分页工作正常,但按降序排列时会加载相同的帖子。我已经考虑过尝试以下替代方案,但它们不具有成本效益:
。
'''
READ_posts__profile(uid,limit, start) : Promise<[]>
{
return new Promise((resolve, reject) =>
{
if (start == null)
{
resolve();
}
else if(start == 'head')
{
start = new Date();
}
console.log(start);
this._DB.collection(this.ref.posts + uid + '/userposts' )
.orderBy("timestamp", 'desc').startAfter(start).limit(limit)
.get()
.then((querySnapshot) =>
{
let obj : any = [];
console.log(obj);
querySnapshot
.forEach((doc : any) => …Run Code Online (Sandbox Code Playgroud) 我正在尝试查询Firestore中的列表,该列表应按降序日期属性排序,并使用startAfter游标对结果进行分页。
正如您在下面的代码片段中看到的那样,一旦我将orderBy('date','desc')与startAfter(lastDoc.date)合并,此操作就会失败。
我想知道我在做什么错。有任何想法吗?
// this actually works
// but it is sorted by ascending dates
db.collection('tanks')
.doc(tankId)
.collection('documentations')
.orderBy('date')
.startAfter(lastDoc.date)
.limit(pageSize)
.get()
// this even works...
// but has no cursor (startAfter) set for pagination
db.collection('tanks')
.doc(tankId)
.collection('documentations')
.orderBy('date', 'desc')
.limit(pageSize)
.get()
// this is what i need
// but it returns always zero results
db.collection('tanks')
.doc(tankId)
.collection('documentations')
.orderBy('date', 'desc')
.startAfter(lastDoc.date)
.limit(pageSize)
.get()Run Code Online (Sandbox Code Playgroud)
javascript firebase google-cloud-firestore react-native-firebase