Within Firebase, I have objects for articles structured like this:
articles
UNIQUE_KEY
title: 'Some title'
validUntil: '2017-09-29T21:00:00.000Z'
UNIQUE_KEY
title: 'Other title'
validUntil: '2017-10-29T21:00:00.000Z'
Currently, I am trying to fetch only those articles whose validUntil
date is in the future. This is the function I've implemented in my service:
getValidArticles(): Observable<Article[]> {
return this.afDb.list('articles').do(console.log)
.scan((article) => {
if (new Date(article.validUntil).getTime() >= new Date().getTime()) {
return article;
}
})
}
It seems to be working fine, but I noticed that upon logging with .do(console.log)
, two identical objects are displayed in the console. I'm not sure if I'm approaching this correctly. Can anyone provide some insight?