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

196
Views
How do I save this in firestore the way I want it to be to be structured?

I have these data:

orders = {
  firstName: "Jennie",
  lastName: "asdasda",
  address: "US",
  order: [
    { product: "Tumbler - 500- ML ", variation: [{ qty: 12, color: "red" }] },
    { product: "Shirt - M ", variation: [{ qty: 14, color: "green" }] }
  ],
  instructions: "asdasdad",
  contact: "182738123"
};

Saving this in firestore would look like this:

enter image description here

How do I save this in firestore where the fields of firstName, lastName, address, contact and instructions is not inside the orders map?

I kind of wanted to save it like this:

enter image description here

This is how I saved it in Firestore:

 const Save = () => {
      const { state } = useStateMachine(updateAction);
      const orders = state.yourDetails;
    
      const handleAdd = async () => {
        try {
          const docRef = await addDoc(collection(db, "orders"), { orders });
          console.log("Document written with ID: ", docRef.id);
        } catch (err) {
          console.log(err);
        }
      };
    
      return (
        <div>
          Results
          <pre>{JSON.stringify(state.yourDetails, null, 2)}</pre>
          <button onClick={handleAdd}>Add </button>
        </div>
      );
    };
    
    export default Save;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

remove the curly bracket from { orders }:

 const Save = () => {
      const { state } = useStateMachine(updateAction);
      const orders = state.yourDetails;
    
      const handleAdd = async () => {
        try {
          const docRef = await addDoc(collection(db, "orders"), orders);
          console.log("Document written with ID: ", docRef.id);
        } catch (err) {
          console.log(err);
        }
      };
    
      return (
        <div>
          Results
          <pre>{JSON.stringify(state.yourDetails, null, 2)}</pre>
          <button onClick={handleAdd}>Add </button>
        </div>
      );
    };
    
    export default Save;
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!