2021年3月13日星期六

Hello. I'm working with mongodb today, and I wanted to add something to a set depending on some conditions

So, say if someone did x then it would add to a set called y, but if someone did y it would add to a set called x My first thought was the ternary operator, and I used the following code:

let toAdd = x ? 'y' : 'x'  // Jump cut to $addToSet  $addToSet: {   toAdd: 'thing'    }  

but it doesn't actually add anything to the database. How could I specify a certain set using a variable?

https://stackoverflow.com/questions/66620020/hello-im-working-with-mongodb-today-and-i-wanted-to-add-something-to-a-set-de March 14, 2021 at 08:49AM

没有评论:

发表评论