Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Query nested objects firebase

I am trying to get the orders from my db where the email property (which is inside the buyer object) is equal to the user's email; but I keep getting an empty array without orders.

const ProfileContainer = () => {
let { user } = useContext(AppContext)

const [orders, setOrders] = useState([])
const [loading, setLoading] = useState(true)

useEffect(() => {
    console.log(orders)
}, [orders])

useEffect(() => {
    const db = getFirestore()
    const ordersRef = query(collection(db, 'orders'), where(('buyer', 'email'), '==', user.email))
    getDocs(ordersRef)
        .then(res => {
            setOrders(res.docs.map((order) => ({ ...order.data() })))
        })
        .finally(() => setLoading(false))
}, [user])

return (
    <>
        {loading ?
            <Spinner />
            :
            <Profile
                orders={orders}
                user={user}

            />
        }
    </>
)
}

This is my db firebase schema

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use dot notation to build the path to the nest field.

const ordersRef = query(
    collection(db, 'orders'),
    where('buyer.email', '==', user.email)
)

See also

  • How to Query a nested field in Firestore?
  • Update fields in nested objects in firestore documents?
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!