i want to query my data by time stamp
let date = new Date();
var today = new Date();
var yesterday = date.setDate(today.getDate() - 1);
console.log(date)
const dataTable = collection(db, 'sales')
let mquery = query(dataTable, where('createdDate', "<", yesterday))
const qSnap = await getDocs(mquery)
console.log(qSnap)
error : Uncaught (in promise) FirebaseError: Expected type ‘mc’, but it was: a custom xh object
2
Answers
You should use the
query
function and createQuery
instance.Documentations to refer to:
The error that you encountered was produced by not using the
query()
method as pointed out by @AyseAsude. Now, after fixing the query, you should also convert the variableyesterday
into adate
format and iterate the items from the query. See code below:For more information, you check out this documentation.