0

Hi there i am trying to insert in my firestore db, i have noticed that the data goes through but if i add it manually in the console the color of the id is diferent, is darker as you can see in the picture.

Id diferences

When i do a query only finds the ones i have inserted manually

In my Home.js i get the datestring value from react native calendars by wix


onDayPress={(day) => { 
          const dateString =day.dateString.toString()
          setDateString(dateString); console.log(dateString) }}
        // Initially selected day

And then in App.js i create my task with the dateString

const createTask = async (collection, data) => {
    //adding data to a collection with automatic id
    //const ref = await addDoc( collection(FSdb, FScollection ), data )
    const ref = await setDoc(doc(FSdb, `usertasks/${user.uid}/events/${data.dateString}/items/${new Date().getTime()}`), data)
    //console.log( ref.id )
  }

I dont know what im doing wrong

Marc Anthony B
  • 3,635
  • 2
  • 4
  • 19
Juan
  • 87
  • 8

1 Answers1

0

I tried to replicate based on the screenshot and code provided. See below for my replication: enter image description here

The issue happens in two cases:

  1. Deleting collection or document with sub collection and sub documents.

  2. Adding collection and documents to an empty document. If you create directly something like /collection/document(1)/collection/document(2)`. You should create it in two steps:

    • create: /collection/document(1)
    • create: /collection/document(1)/collection/document(2)

The italicized document IDs shown in the UI actually doesn't exist but its still shown so that you can still navigate to the subcollections. Since there is no document, the document itself will not show up in query results. If you want any document to exist, you have to write some code to create it and give it some fields. If you never explicitly create a document, then it never exists.

You may also refer on this documentation for more information.

Marc Anthony B
  • 3,635
  • 2
  • 4
  • 19
  • thanks. And now why isnt working this query? let eventsOfTheDay = [] const eventKeys = Object.keys( eventData ) eventKeys.map( async (eventDate) => { const events = await getDocs( FSdb, `users/${user.uid}/events/${eventDate}/items`) events.forEach( (doc) => { let event = doc.data() event.id = doc.id eventsOfTheDay.push( event ) }) comes empty of values when i pass it? – Juan Dec 14 '21 at 12:42
  • Hi @Juan, it appears to be a new question already. Please post a new question so other people can contribute to answer it. Thank you. – Marc Anthony B Dec 15 '21 at 09:27
  • I am trying this await setDoc(doc(FSdb, `usertasks/${user.uid}`), data) await setDoc(doc(FSdb, `usertasks/${user.uid}/events/${data.dateString}`), data) await setDoc(doc(FSdb, `usertasks/${user.uid}/events/${data.dateString}/items/${new Date().getTime()}`), data) And isnt working as is assigning fields to item and events. Not sure why. Would you mind to show my the right line of code to get the same but the fields just inside items?? thanks – Juan Dec 15 '21 at 23:18