Update item in array, getting error “The positional operator did not find the match needed from the...
up vote
0
down vote
favorite
I'm trying to update array element inside document.
The document looks like this:
{
"_id": "11111ec6de08e20354634b1d",
"firstname": "Israel",
"lastname": "Lavi",
"exams": [
{
"examId": "1000",
"name": "something",
"status": [
{
"status": "created",
"date": "2018-11-09T08:01:46.627Z"
}
]
},
{
"examId": "2000",
"name": "something",
"status": [
{
"status": "created",
"date": "2018-11-09T08:01:46.627Z"
}
]
}
]
}
I want to update exam where examId=1000
I'm using the following command:
collection.update({'_id': _id, 'exams': { $elemMatch : { 'examId': examId } } }, {$set: {'exams.$': lcExam}}, {upsert: true})
And getting the following error:
The positional operator did not find the match needed from the query.
Thanks in advance
mongodb
|
show 2 more comments
up vote
0
down vote
favorite
I'm trying to update array element inside document.
The document looks like this:
{
"_id": "11111ec6de08e20354634b1d",
"firstname": "Israel",
"lastname": "Lavi",
"exams": [
{
"examId": "1000",
"name": "something",
"status": [
{
"status": "created",
"date": "2018-11-09T08:01:46.627Z"
}
]
},
{
"examId": "2000",
"name": "something",
"status": [
{
"status": "created",
"date": "2018-11-09T08:01:46.627Z"
}
]
}
]
}
I want to update exam where examId=1000
I'm using the following command:
collection.update({'_id': _id, 'exams': { $elemMatch : { 'examId': examId } } }, {$set: {'exams.$': lcExam}}, {upsert: true})
And getting the following error:
The positional operator did not find the match needed from the query.
Thanks in advance
mongodb
1
Looks fine to me, except maybe Is thatexamId = 1000
orexamId = "1000"
? Note that one is a string and therefore the only match. Either that or are you maybe using CosmosDB?
– Neil Lunn
2 days ago
examId is string, I'm using Typegoose
– Israel
2 days ago
1
That part kind of does not matter here. For mongoose the "schema" might have some importance, so you should include it in your question in order to ensure nothing is being rewritten incorrectly. As long as it's a string ( or the schema is indeed a string ) then it's fine. I asked about "CosmosDB" because that is a product which does "MongoDB emulation", but actually quite badly thus leading to reported errors like your one. So those are the things you are actually being asked. Cannot reproduce on vanilla MongoDB.
– Neil Lunn
2 days ago
1
The error is because of the"upsert"
option. The problem here is that the "document" may well exist, but the "array item" within the document may not be present. For this reason "upserts" don't really mix well as a pattern when you have arrays of sub-documents inside the documents. This means you need to be very careful and typically construct multiple statements in order to handle all cases.
– Neil Lunn
2 days ago
1
There's some more detail you should read at mongoDB upsert on array which talks about the process further. Due to it's age it shows the direct "command" format for invoking multiple updates which are now covered directly in the collectionbulkWrite()
method for every driver.
– Neil Lunn
2 days ago
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to update array element inside document.
The document looks like this:
{
"_id": "11111ec6de08e20354634b1d",
"firstname": "Israel",
"lastname": "Lavi",
"exams": [
{
"examId": "1000",
"name": "something",
"status": [
{
"status": "created",
"date": "2018-11-09T08:01:46.627Z"
}
]
},
{
"examId": "2000",
"name": "something",
"status": [
{
"status": "created",
"date": "2018-11-09T08:01:46.627Z"
}
]
}
]
}
I want to update exam where examId=1000
I'm using the following command:
collection.update({'_id': _id, 'exams': { $elemMatch : { 'examId': examId } } }, {$set: {'exams.$': lcExam}}, {upsert: true})
And getting the following error:
The positional operator did not find the match needed from the query.
Thanks in advance
mongodb
I'm trying to update array element inside document.
The document looks like this:
{
"_id": "11111ec6de08e20354634b1d",
"firstname": "Israel",
"lastname": "Lavi",
"exams": [
{
"examId": "1000",
"name": "something",
"status": [
{
"status": "created",
"date": "2018-11-09T08:01:46.627Z"
}
]
},
{
"examId": "2000",
"name": "something",
"status": [
{
"status": "created",
"date": "2018-11-09T08:01:46.627Z"
}
]
}
]
}
I want to update exam where examId=1000
I'm using the following command:
collection.update({'_id': _id, 'exams': { $elemMatch : { 'examId': examId } } }, {$set: {'exams.$': lcExam}}, {upsert: true})
And getting the following error:
The positional operator did not find the match needed from the query.
Thanks in advance
mongodb
mongodb
asked 2 days ago
Israel
547
547
1
Looks fine to me, except maybe Is thatexamId = 1000
orexamId = "1000"
? Note that one is a string and therefore the only match. Either that or are you maybe using CosmosDB?
– Neil Lunn
2 days ago
examId is string, I'm using Typegoose
– Israel
2 days ago
1
That part kind of does not matter here. For mongoose the "schema" might have some importance, so you should include it in your question in order to ensure nothing is being rewritten incorrectly. As long as it's a string ( or the schema is indeed a string ) then it's fine. I asked about "CosmosDB" because that is a product which does "MongoDB emulation", but actually quite badly thus leading to reported errors like your one. So those are the things you are actually being asked. Cannot reproduce on vanilla MongoDB.
– Neil Lunn
2 days ago
1
The error is because of the"upsert"
option. The problem here is that the "document" may well exist, but the "array item" within the document may not be present. For this reason "upserts" don't really mix well as a pattern when you have arrays of sub-documents inside the documents. This means you need to be very careful and typically construct multiple statements in order to handle all cases.
– Neil Lunn
2 days ago
1
There's some more detail you should read at mongoDB upsert on array which talks about the process further. Due to it's age it shows the direct "command" format for invoking multiple updates which are now covered directly in the collectionbulkWrite()
method for every driver.
– Neil Lunn
2 days ago
|
show 2 more comments
1
Looks fine to me, except maybe Is thatexamId = 1000
orexamId = "1000"
? Note that one is a string and therefore the only match. Either that or are you maybe using CosmosDB?
– Neil Lunn
2 days ago
examId is string, I'm using Typegoose
– Israel
2 days ago
1
That part kind of does not matter here. For mongoose the "schema" might have some importance, so you should include it in your question in order to ensure nothing is being rewritten incorrectly. As long as it's a string ( or the schema is indeed a string ) then it's fine. I asked about "CosmosDB" because that is a product which does "MongoDB emulation", but actually quite badly thus leading to reported errors like your one. So those are the things you are actually being asked. Cannot reproduce on vanilla MongoDB.
– Neil Lunn
2 days ago
1
The error is because of the"upsert"
option. The problem here is that the "document" may well exist, but the "array item" within the document may not be present. For this reason "upserts" don't really mix well as a pattern when you have arrays of sub-documents inside the documents. This means you need to be very careful and typically construct multiple statements in order to handle all cases.
– Neil Lunn
2 days ago
1
There's some more detail you should read at mongoDB upsert on array which talks about the process further. Due to it's age it shows the direct "command" format for invoking multiple updates which are now covered directly in the collectionbulkWrite()
method for every driver.
– Neil Lunn
2 days ago
1
1
Looks fine to me, except maybe Is that
examId = 1000
or examId = "1000"
? Note that one is a string and therefore the only match. Either that or are you maybe using CosmosDB?– Neil Lunn
2 days ago
Looks fine to me, except maybe Is that
examId = 1000
or examId = "1000"
? Note that one is a string and therefore the only match. Either that or are you maybe using CosmosDB?– Neil Lunn
2 days ago
examId is string, I'm using Typegoose
– Israel
2 days ago
examId is string, I'm using Typegoose
– Israel
2 days ago
1
1
That part kind of does not matter here. For mongoose the "schema" might have some importance, so you should include it in your question in order to ensure nothing is being rewritten incorrectly. As long as it's a string ( or the schema is indeed a string ) then it's fine. I asked about "CosmosDB" because that is a product which does "MongoDB emulation", but actually quite badly thus leading to reported errors like your one. So those are the things you are actually being asked. Cannot reproduce on vanilla MongoDB.
– Neil Lunn
2 days ago
That part kind of does not matter here. For mongoose the "schema" might have some importance, so you should include it in your question in order to ensure nothing is being rewritten incorrectly. As long as it's a string ( or the schema is indeed a string ) then it's fine. I asked about "CosmosDB" because that is a product which does "MongoDB emulation", but actually quite badly thus leading to reported errors like your one. So those are the things you are actually being asked. Cannot reproduce on vanilla MongoDB.
– Neil Lunn
2 days ago
1
1
The error is because of the
"upsert"
option. The problem here is that the "document" may well exist, but the "array item" within the document may not be present. For this reason "upserts" don't really mix well as a pattern when you have arrays of sub-documents inside the documents. This means you need to be very careful and typically construct multiple statements in order to handle all cases.– Neil Lunn
2 days ago
The error is because of the
"upsert"
option. The problem here is that the "document" may well exist, but the "array item" within the document may not be present. For this reason "upserts" don't really mix well as a pattern when you have arrays of sub-documents inside the documents. This means you need to be very careful and typically construct multiple statements in order to handle all cases.– Neil Lunn
2 days ago
1
1
There's some more detail you should read at mongoDB upsert on array which talks about the process further. Due to it's age it shows the direct "command" format for invoking multiple updates which are now covered directly in the collection
bulkWrite()
method for every driver.– Neil Lunn
2 days ago
There's some more detail you should read at mongoDB upsert on array which talks about the process further. Due to it's age it shows the direct "command" format for invoking multiple updates which are now covered directly in the collection
bulkWrite()
method for every driver.– Neil Lunn
2 days ago
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373152%2fupdate-item-in-array-getting-error-the-positional-operator-did-not-find-the-ma%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Looks fine to me, except maybe Is that
examId = 1000
orexamId = "1000"
? Note that one is a string and therefore the only match. Either that or are you maybe using CosmosDB?– Neil Lunn
2 days ago
examId is string, I'm using Typegoose
– Israel
2 days ago
1
That part kind of does not matter here. For mongoose the "schema" might have some importance, so you should include it in your question in order to ensure nothing is being rewritten incorrectly. As long as it's a string ( or the schema is indeed a string ) then it's fine. I asked about "CosmosDB" because that is a product which does "MongoDB emulation", but actually quite badly thus leading to reported errors like your one. So those are the things you are actually being asked. Cannot reproduce on vanilla MongoDB.
– Neil Lunn
2 days ago
1
The error is because of the
"upsert"
option. The problem here is that the "document" may well exist, but the "array item" within the document may not be present. For this reason "upserts" don't really mix well as a pattern when you have arrays of sub-documents inside the documents. This means you need to be very careful and typically construct multiple statements in order to handle all cases.– Neil Lunn
2 days ago
1
There's some more detail you should read at mongoDB upsert on array which talks about the process further. Due to it's age it shows the direct "command" format for invoking multiple updates which are now covered directly in the collection
bulkWrite()
method for every driver.– Neil Lunn
2 days ago