Liam Sholts
Liam Sholts

Reputation: 85

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.

Upvotes: 0

Views: 83

Answers (1)

nimrod serok
nimrod serok

Reputation: 16033

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

Upvotes: 2

Related Questions