1

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 2

2

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 variable yesterday into a date format and iterate the items from the query. See code below:

let date = new Date();
var today = new Date();
var yesterday = new Date(date.setDate(today.getDate() - 1));

const dataTable = collection(db, 'sales')
let mquery = query(dataTable, where('createdDate', "<", yesterday))
const qSnap = await getDocs(mquery)

qSnap.forEach((doc) => {
  // doc.data() is never undefined for query doc snapshots
  console.log(doc.id, " => ", doc.data());
});

For more information, you check out this documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

this is soo good to hear from you. I am thankful to you. thank you so so much.
please have a look on this question to stackoverflow.com/questions/73064340/…
1

You should use the query function and create Query instance.

import {query} from "firebase/firestore";

let mquery = query(dataTable, where('createdDate', "<", yesterday))
const qSnap = await getDocs(mquery)

Documentations to refer to:

1 Comment

thank you but this is not working for me this is my last code let date = new Date(); var today = new Date(); var yesterday = date.setDate(today.getDate() - 3); console.log(yesterday) const dataTable = collection(db, 'sales') let mquery = query(dataTable, where('createdDate', ">", yesterday)) const qSnap = await getDocs(mquery)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.