These are chat archives for Automattic/mongoose

29th
Aug 2018
ratnesh2581990
@ratnesh2581990
Aug 29 2018 06:49
@lineus getting error from mongo db that this index was not found
ratnesh2581990
@ratnesh2581990
Aug 29 2018 08:07
@lineus Thank you very much you help me a lot in solving my problem. you saved my project otherwise client will take the project back from me.
Kev
@lineus
Aug 29 2018 12:08
@ratnesh2581990 I'm really glad I could help :smile:
mirik999
@mirik999
Aug 29 2018 20:29
@lineus Hi again, i am here from github
Kev
@lineus
Aug 29 2018 20:51
Hi @mirik999
mirik999
@mirik999
Aug 29 2018 20:52
i must write the same question here ?
Kev
@lineus
Aug 29 2018 20:52
no :) sorry I'm just wrapping something up. give me a few minutes and I'll give you my undivided attention.
mirik999
@mirik999
Aug 29 2018 20:53
ok
Kev
@lineus
Aug 29 2018 21:02
@mirik999 what is the value of data in your editedPlayer listener?
does it contain all of the fields of the player?
mirik999
@mirik999
Aug 29 2018 21:06
Yes
i have all data what i need
i want just a way how to implement
Kev
@lineus
Aug 29 2018 21:10
I think the easiest way would be to replace Player.findById() with
  Player.findByIdAndUpdate(data.editedPlayer._id, data.editedPlayer, (err, player) => {
    if (err) { return console.error(err) }
    return console.log('updated player')
  })
mirik999
@mirik999
Aug 29 2018 21:26
@lineus findById changed findByIdAndUpdate but i need to update in player model in nested array -> specific object
i have _id for searching player , i have a new count for updating and i have the seller _id for updating only specific seller count. Because in ona players can be many sellers and every seller can update own count.
P.S. sorry for my crooked english
Kev
@lineus
Aug 29 2018 21:30
your english is 1.6784 million times better than my < insert your language here>.
Kev
@lineus
Aug 29 2018 21:41
@mirik999 here is an example of updating a path of a specific seller based on the id of the seller.
the function sellerCountChanged() finds the player by id, then updates the specific doc in the array based on it's id
mirik999
@mirik999
Aug 29 2018 22:19
I did it , maybe with a wrong way but it works. Thanx @lineus , your code helped me a lot.
socket.on('editedPlayer', async data => {

      Player.findOne({ _id: data.editedPlayer._id }, (err, player) => {
        player.silver.map((pl, idx) => {
          if (pl.seller == data.seller) {
            pl.set('count', data.newCount)
            return player.save();
          }
        })
      })

    })
Kev
@lineus
Aug 29 2018 23:35
I'm glad you got it sorted out @mirik999 :smile: