title: Firestore addDoc error:Invalid document reference. Document references must have an even number of segments, but
body: <p>I would like to save  my data to firestore in React.js app but Firestore returns me Invalid document reference. Document references must have an even number of segments, but</p>
  <p>Firebase Config file</p>
  <pre><code>import { initializeApp,} from &quot;firebase/app&quot;;
  import {getAuth} from 'firebase/auth'
  import {getFirestore} from &quot;firebase/firestore&quot;
  
  const firebaseConfig = {
      apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
      authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
      projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
      storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
      messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
      appId:process.env.REACT_APP_FIREBASE_APP_ID,
      measurementId: process.env.REACT_APP_FIREBASE_MEASUREMENT_ID
    };
  
    const app =initializeApp(firebaseConfig);
    export const db=getFirestore(app);
    export const auth= getAuth(app)
  </code></pre>
  <p>and it is my code for saving data to firebase with addDoc</p>
  <pre><code>    try{ 
          const user = await createUserWithEmailAndPassword(auth,email,password);
           const data={
              userId:user.user.uid,
              name: &quot;Pls set name&quot;,
              about:&quot;Pls set about&quot;,
              profileImg:&quot;&quot;,
              contacts:[
                  &quot;&quot;,
              ]
          }
          const docRef =doc(collection(db,`/users/`));
          await addDoc(docRef,data);
          return user
      }catch(err){
          console.log(err.message)
      }
  </code></pre>
  <p>lastly screenshot of error</p>
  <p><a href="https://i.stack.imgur.com/Z8QIH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z8QIH.png" alt="enter image description here" /></a></p>