You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
Setting the content of an array of arrays throws a MongoError: The positional operator did not find the match needed from the query.
Doing exactly the same update with updateOne works fine.
If the current behavior is a bug, please provide the steps to reproduce.
Assuming a connection to a mongo server has been established, the following jest test should demonstrate the issue (I have the same bug outside of the jest environment I just used it for convenience):
describe('Test mongoose',()=>{constschema=newmongoose.Schema({name: String,array: [[{label: String,value: String,}]],});constMyModel=mongoose.model('MyModel',schema);constupdateQuery={'array.0': [{label: 'hello',value: 'world',}],};test('It works to update nested array using updateOne',async()=>{constdoc=awaitnewMyModel({name: 'foo'}).save();awaitMyModel.updateOne({_id: doc._id},{$set: updateQuery});constupdatedDoc=awaitMyModel.findOne({_id: doc._id});expect(updatedDoc.array[0][0].label).toBe('hello');expect(updatedDoc.array[0][0].value).toBe('world');// Success!});test('It works to update nested array using set',async()=>{constdoc=awaitnewMyModel({name: 'foo'}).save();awaitdoc.set(updateQuery).save();// Fails MongoError: The positional operator did not find the match needed from the query.constupdatedDoc=awaitMyModel.findOne({_id: doc._id});expect(updatedDoc.array[0][0].label).toBe('hello');expect(updatedDoc.array[0][0].value).toBe('world');});});
After a git bisect I have found the commit that caused the issue: 51c6776
Downgrading to 5.7.12 fixes the issue.
What is the expected behavior?
Should update the nested array using doc.set
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: 5.7.13
mongoDB: 4.2.0
Node: 10.16.0
The text was updated successfully, but these errors were encountered:
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Mar 23, 2020
Uh oh!
There was an error while loading. Please reload this page.
Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
Setting the content of an array of arrays throws a MongoError: The positional operator did not find the match needed from the query.
Doing exactly the same update with
updateOne
works fine.If the current behavior is a bug, please provide the steps to reproduce.
Assuming a connection to a mongo server has been established, the following jest test should demonstrate the issue (I have the same bug outside of the jest environment I just used it for convenience):
After a git bisect I have found the commit that caused the issue: 51c6776
Downgrading to 5.7.12 fixes the issue.
What is the expected behavior?
Should update the nested array using
doc.set
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: 5.7.13
mongoDB: 4.2.0
Node: 10.16.0
The text was updated successfully, but these errors were encountered: