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
Hi, thanks for this library, it is very useful. I may have stumbled across a small issue with upsert and subsequent matching on Mongo identifiers. A repro of the issue is below.
// Using updateOne(..., { upsert: true }) with an existing identifier. The expectation here is that // upserted record would use the identifier passed in the filter. However that doesn't// appear to be the case.asyncfunctionrepro(){constmongo_mock=require('mongo-mock')constclient=newmongo_mock.MongoClient()constdb=awaitclient.connect('mongodb://localhost:27017/db')constvectors=db.collection('vectors')const_id=newmongo_mock.ObjectID()constupdateResult=awaitvectors.updateOne({ _id },{x: 1,y: 2,z: 3},{upsert: true})constfindResult=awaitvectors.findOne({ _id })console.log(updateResult)// result: { result: { ok: 1, nModified: 1, n: 1 }, ... }console.log(findResult)// result: null// expect: { _id: ObjectId(...), x: 1, y, 2, z: 3 }}repro()
I can confirm the record is being written with this subsequent repro, however unsure about the encoding used to express the identifier, or why this is failing to match. (Edit: it appears mongo-mock may just be ignoring the _id for the filter and generating a new _id in these cases)
asyncfunctionrepro2(){constmongo_mock=require('mongo-mock')constclient=newmongo_mock.MongoClient()constdb=awaitclient.connect('mongodb://localhost:27017/db')constvectors=db.collection('vectors')const_id=newmongo_mock.ObjectID()constupdateResult=awaitvectors.updateOne({ _id },{x: 1,y: 2,z: 3},{upsert: true})constfindResult=awaitvectors.findOne({})// omitconsole.log(_id)// ObjectID(620ca8968d741e4d0099b507)console.log(findResult)// {// x: 1,// y: 2,// z: 3,// _id: { _bsontype: 'ObjectID', id: 'b\f¨\x96\x8Dt\x1EM\x00\x99µ\x07' }// } ^// ObjectID is returned with the .id encoded as an escaped string}repro2()
Running comparative tests against MongoDB itself yields the expected behavior.
The text was updated successfully, but these errors were encountered:
Hi, thanks for this library, it is very useful. I may have stumbled across a small issue with
upsert
and subsequent matching on Mongo identifiers. A repro of the issue is below.I can confirm the record is being written with this subsequent repro, however unsure about the encoding used to express the identifier, or why this is failing to match. (Edit: it appears mongo-mock may just be ignoring the
_id
for the filter and generating a new_id
in these cases)Running comparative tests against MongoDB itself yields the expected behavior.
The text was updated successfully, but these errors were encountered: