Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: / ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!mongodb bulkWrites update behaves differently from normal update
I have a document with an order array that contains ids.
Sometimes I want to set specific indexes in that array:
db.getCollection('myCollection').update(
{
_id: 'someId',
},
{
$set: {
'order.1': 'foo2',
},
},
);
db.getCollection('myCollection').update(
{
_id: 'someId',
},
{
$set: {
'order.1': 'foo2',
},
},
);
This works correcly and updates the second array element. If the array is empty, the 0th element is null.
Trying the same with bulkWrite leads to really weird behavior:
db.getCollection('myCollection').bulkWrite([
{
updateOne: {
filter: { _id: 'eager' },
update: [
{
$set: {
'order.1': 'foo3',
},
},
],
},
},
]);
db.getCollection('myCollection').bulkWrite([
{
updateOne: {
filter: { _id: 'eager' },
update: [
{
$set: {
'order.1': 'foo3',
},
},
],
},
},
]);
If the array in the db is empty this does nothing.
However, if there are elements in the array, this replaces every array element with an object of the form { '1': 'foo3' }.
every
{ '1': 'foo3' }
Does anyone have any idea why this happens and how to make bulkWrite behave? :D
Tags: javascript,arrays,mongodbSource of the question:
https://stackoverflow.com/questions/7...
Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/
Информация по комментариям в разработке