Answer the question
In order to leave comments, you need to log in
Error when using $switch statement, where is the error?
People, I ask for help. Recently I took up mongo and there is such an error, I seem to do everything according to the documentation, but nothing comes out ...
Error:
Scheme:
const mongoose = require('mongoose');
const users = mongoose.Schema({
vkid: Number,
pers: {
lucky: Number
}
});
module.exports = mongoose.model('Users', users);
await users.updateMany({ vkid: id }, {
$set: {
"pers.lucky": {
$switch: {
branches: [
{ case: message.messagePayload.command === 'первый', then: 1 },
{ case: message.messagePayload.command === 'второй', then: 2 },
{ case: message.messagePayload.command === 'третий', then: 3 }
], default: 69
}
}
}
});
await users.updateMany({ vkid: id }, {
$set: {
"pers.lucky": 5
}
});
Answer the question
In order to leave comments, you need to log in
you need to use the $eq operator instead of ===
await users.updateMany({ vkid: id }, {
$set: {
"pers.lucky": {
$switch: {
branches: [
{
case: {$eq: ["$message.messagePayload.command", 'первый',]},
then: 1
}, ], default: 69
}
}
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question