Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

399
Visualizações
Why don't documents that I get from a collection have the collection() method?

I am trying to loop through a collection of users, which are documents, in my firestore database. The user documents I get, have subcollections within them. Within these subcollections, I want to add a document. I am currently at the point of adding the document to the subcollection, but I am being told that the collection method does not exist because userDoc is still in a promise which doesn't make any sense because when I print the id of the userDoc I get the id of the document in firestore. Error:

Uncaught (in promise) TypeError: userDoc.collection is not a function

My code is below.

async function preformSignaling() {
  let users = await negDoc.collection("users").get();

  for (let userDoc of users.docs) {
    if (isNotAlreadyConnected(userDoc.id)) {
      let newPeerConnection = new UserConnection(servers, userDoc.id);

      if (
        userDoc.id != sessionStorage.getItem("userID") &&
        userDoc.id != "metadata"
      ) {
        let connOfferDescription =
          await newPeerConnection.userPeerConnection.createOffer();

        await newPeerConnection.userPeerConnection.setLocalDescription(
          connOfferDescription
        );

        await userDoc.collection("offer-candidates").doc("offer").set({
          offer: newPeerConnection.userPeerConnection.localDescription,
        });
      }

      peerConnections.push(newPeerConnection);
    }
  }
}

class UserConnection {
  constructor(servers, remoteUserID) {
    this.userPeerConnection = new RTCPeerConnection(servers);
    this.remoteStream = new MediaStream();
    this.remoteUserID = remoteUserID;

  getRemoteUserID() {
    return this.remoteUserID;
  }
}

Concerned Code:

await userDoc.collection("offer-candidates").doc("offer").set({
              offer: newPeerConnection.userPeerConnection.localDescription,
            });
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

The problem doesn't have anything to do with promises; you're awaiting what you're supposed to await. The issue is that userDoc is a document snapshot (ie, the result of querying the database), and document snapshots don't have a .collection method. They basically just have a .data() method, and then some metadata properties (eg, .id, .exists)

Instead, you need to do the following:

await negDoc
  .collection("users")
  .doc(userDoc.id)
  .collection("offer-candidates")
  .doc("offer")
  .set({
    offer: newPeerConnection.userPeerConnection.localDescription,
  });
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda