简体   繁体   English

使用服务器时间戳进行过滤

[英]Using server timestamp for filtering

Firebase provides a mechanism to insert server timestamps . Firebase提供了一种插入服务器时间戳的机制。

I was wondering if it also can be used for filtering. 我想知道它是否也可用于过滤。 Like this: 像这样:

var db = firebase.database();
var path = '/some/path';
var ref = db.ref(path);
ref.orderByChild('ts')
    .startAt(firebase.database.ServerValue.TIMESTAMP)
    .on('child_added', function(snap) {
        //do something
    });

Error: Query: First argument passed to startAt(), endAt(), or equalTo() cannot be an object. 错误:查询:传递给startAt(),endAt()或equalTo()的第一个参数不能是对象。

Assuming you've already set the 'ts' child of a bunch of entries, you would add an actual timestamp to your startAt method like startAt('1473645571228') . 假设您已经设置了一堆条目的'ts'子项,您可以在startAt方法中添加一个实际时间戳,如startAt('1473645571228')

You can create the Unix timestamp client side with Moment.js, or if you need it from Firebase, you can quickly set and retrieve it . 您可以使用Moment.js创建Unix时间戳客户端,或者如果您需要Firebase,则可以快速设置和检索它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM