#Update an element of the object of a collection

5 messages · Page 1 of 1 (latest)

stoic hill
#

In a collection i have a value of object more than 1 element, suppose if I want to update the value of one of the elements of the object, how do I do so without overwriting the whole object?

Eg -

// original collection.

Collection(1) [Map] {
  '968129136818266192' => {
    players: [ [Promise] ],
    text_channel: '968129064030310460',
    map: 'none',
    highest_votes: 0,
    total_votes: 0,
    map_wise_votes: []
  }
}

// After using collection.set(key, { players: 'something' });

Collection(1) [Map] {
  '968129136818266192' => { players: [ [Promise] ] }
}

doing this overwrites the data but I dont want that, I only want to update the value of players and keep the rest of the data as it is.

near fiberBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

gritty tartan
#

Get the element, change the property, set the element again

stoic hill
#
let coll = collection.get('968129136818266192');
coll.players = [];

collection.set('968129136818266192', coll);```
#

like this?