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

297
Views
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 answers
Answer question

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 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!