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

301
Visualizações
why are the elements in array being stored as an integer, instead of the actual value in MongoDB?

I am creating a chat website. In the chat website, you may direct message any user as long as you know their username. Once you type in the username, it creates a new document in the "Groups" database. Here is the schema:

users: Array

dmId: String

dmSecret: String

messages: Array

I know I probably could've made the secure thing a lot easier, but that's not them. For some reason, when I am adding the group chat ID to an array inside a user document, it just comes out as

Thats weird, it was supposed to equal

["whatever group id"]

not

[2]

Here is how I am storing this (mongoose)

(Friend is the user document, and "newDmID" is the correct value, not 1 or 2, also I only use this if there is not already an array there`

friend[0].dms = new Array().push(newDmID)

I have bad english, sorry if I am not clear.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In Node.js this is not a proper way to initiate an array. Use:

friend[0].dms = [newDmID]

OR:

friend[0].dms = new Array(newDmID)

This is not a mongoDB issue

about 4 years ago · Juan Pablo Isaza 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