Firebase查询按创建时间过滤,其中日期大于现在 [英] Firebase Query filtered by creation time and where date is greater than now

查看:119
本文介绍了Firebase查询按创建时间过滤,其中日期大于现在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的应用程序在某个特定时间创建了帖子,他们包含一定的时间。

我用以下方式存储我的数据:

 posts:{
postid1:{
author:{
full_name:author1,
uid:idauthor1
$ bdate:1474455840809,
description:,
title:Test 1
},
postid2 :{
author:{
full_name:author1,
uid:idauthor1
},
date:1480424400622,
description:,
title:Test 2
}
}

postID 是自动生成的,所以应该足以按创建时间排序,但是我也想排除( now )。



Doe有人知道我怎么可以/应该这样做吗?
解决方案

我想你是保存日期与ServerValue.Timestamp 。

我想你想实现的是不可能的直接,因为你应该通过一个日期(今天)作为参数,你不能把ServerValue.Timestamp。

我会做的是以这种方式查询所有帖子: ref.orderByChild(date)

然后在客户端过滤。

编辑
这个应该工作。 (它返回与今天之后,当地时间的职位)

  query.orderByChild(date)。startAt(new DateTime ).getMillis())

然后,您应该通过客户端中的键进行订购


I'm kinda new to Firebase and I'm trying to create an app with it.

My app has posts that are created at a certain time and they contain a certain time.

I store my data the following way :

"posts" : {
    "postid1" : {
      "author" : {
        "full_name" : "author1",
        "uid" : "idauthor1"
      },
      "date" : 1474455840809,
      "description" : "",
      "title" : "Test 1"
    },
    "postid2" : {
      "author" : {
        "full_name" : "author1",
        "uid" : "idauthor1"
      },
      "date" : 1480424400622,
      "description" : "",
      "title" : "Test 2"
    }
}

The postID is generated automatically so that should be enough to order them by creation time, but I also want to exclude the ones where the date is past today (now).

Does anyone have an idea how I could/should do that?

解决方案

I suppose you are saving date with "ServerValue.Timestamp".

I think what you want to achieve is not possible directly because you should pass a date (today) as an argument, and you can't put ServerValue.Timestamp.

What I would do is to query all the posts this way: ref.orderByChild("date")

And then filtering in client-side.

EDIT This should work. (it returns posts with date after today, local time)

query.orderByChild("date").startAt(new DateTime().getMillis())

Then you should order by key in client-side

这篇关于Firebase查询按创建时间过滤,其中日期大于现在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆