Javascript 结合文本和日期的Firebase实时数据库复合查询
我正在尝试进行一个复合查询(组合两个孩子)。我要做的是获取早于5分钟的对象,并且也是一种类型的对象 因此,我将子项Javascript 结合文本和日期的Firebase实时数据库复合查询,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,我正在尝试进行一个复合查询(组合两个孩子)。我要做的是获取早于5分钟的对象,并且也是一种类型的对象 因此,我将子项type和date组合成一个名为type\u date的新子项,我的查询如下: const now = Date.now(); const fiveMinutesMs = 5*60*1000; const fiveMinutesAgo = now - fiveMinutesMs; const fiveMinutesAgoQuery = "type_" + fiveMinutesAg
type
和date
组合成一个名为type\u date
的新子项,我的查询如下:
const now = Date.now();
const fiveMinutesMs = 5*60*1000;
const fiveMinutesAgo = now - fiveMinutesMs;
const fiveMinutesAgoQuery = "type_" + fiveMinutesAgo;
ref.orderByChild('type_date').endAt(fiveMinutesAgoQuery).once('value');
唯一的问题是它不起作用。它给我的对象的结果甚至没有
类型\u date
子对象。尝试startAt而不是endAt。我希望它能起作用。尝试开始而不是结束。我希望它能起作用。编辑:哎呀,我太快了。。。。只有当我只过滤日期字符串,而不是与我想要的前置类型一起过滤时,它才起作用
所以这是可行的:
const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();
const fiveMinutesAgoQuery = String(fiveMinutesAgoIso);
但不是:
const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();
const fiveMinutesAgoQuery = "type_" + fiveMinutesAgoIso;
编辑:哎呀,我太快了。。。。只有当我只过滤日期字符串,而不是与我想要的前置类型一起过滤时,它才起作用 所以这是可行的:
const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();
const fiveMinutesAgoQuery = String(fiveMinutesAgoIso);
但不是:
const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();
const fiveMinutesAgoQuery = "type_" + fiveMinutesAgoIso;
只需进行复合查询,如doc所述:
const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();
ref.where("type", "==", TYPE_YOU_WANT).orderByChild('type').endAt(fiveMinutesAgoQuery).once('value');
只需进行复合查询,如doc所述:
const fiveMinutesAgoIso = new Date(fiveMinutesAgo).toISOString();
ref.where("type", "==", TYPE_YOU_WANT).orderByChild('type').endAt(fiveMinutesAgoQuery).once('value');
您的确切数据模型是什么?您在
type_date
字段中存储了什么?我将type与date组合存储在ms中,例如“type_1551172088724”。您能提供您的数据样本吗?您的确切数据模型是什么?您在type_date
字段中存储了什么?我将type与date组合存储在ms中,例如“type_1551172088724”。您能提供您的数据样本吗?