Question about Collection.update, i need a bit of help

Hello guys, it’s me again, in troubles.

Im developing a little jackpot game, and i need to let users update their first bet, before the time is gone. “The snipping thing”.

So, after every user make their first bet, they should have a chance to do some more bets before time is gone.

All that thing is set up, but i dont know how to make each user update his entry. This is how looks the Collection, after users make theyr first bet:

c2a36b943699dfd3d4c2d9bdf56506c8

So i will like to make every user update his betAmount, but i tryed so hard and im not able to find how can users update their owns entry and not the full entry.

So my question is: How can i do , to make every users update his own entry? Instead of the full set?

Im looking for something like:

let doc = Jackpot.update({ .. } , {}); 

By the way, im working with ReactJS …
Thanks for read, hope someone can help me a bit.

Refer MongoDB document https://docs.mongodb.com/manual/reference/operator/update/positional/

2 Likes

This is how I’d approach this with de-normalization: create a separate collection for the roundPlayers, so you can insert and update a player’s betAmount by referencing their _id.
For example

....
roundPlayers.update({userId : nJjdgKkebKkfnnekNhbr, roundId: 110}, {$set :{betAmount : 1200}})

…this is a simple approach and it should work.
P.S.: Adding the roundId lets you update betAmount based on the current round. You can always add other unique pointers per your use case.

1 Like

Hey martineboh, i think u are totally right ( i dont know why i dont think about it before ).

I will try it, thanks you so much for the reply, and the time u spend on it!

Thanks!

1 Like