Skip to content

В relationHooks.js отсутствуют хуки beforeReplaceOne/afterReplaceOne #6

Description

@lbeschastny

В файле relationHooks.js регистрируются хуки на обновление документов в коллекции, на которую были созданые ссылки. Но обновить документ можно не только через update, но и через replace. Соответственно, использование replace может привести к наружению целостности базы.

Пример для воспроизведения проблемы: https://gist.github.com/lbeschastny/ac0908c4b61facad848ded7eb6f48102

Запустить пример можно командой:

git clone git@gist.github.com:ac0908c4b61facad848ded7eb6f48102.git && cd ac0908c4b61facad848ded7eb6f48102 && npm i && node .

По логам видно:

creating document in coll2
document created:
{ foreignKey: { _id: 5b0b0596a7cf640eae5e4085, foo: 'bar' },
  _id: 5b0b0596a7cf640eae5e4086 }


updating document in coll1
document updated:
{ _id: 5b0b0596a7cf640eae5e4085, foo: 'baz' }


reading document in coll2
document fetched:
{ _id: 5b0b0596a7cf640eae5e4086,
  foreignKey: { _id: 5b0b0596a7cf640eae5e4085, foo: 'baz' } }


replacing document in coll1
document updated:
{ _id: 5b0b0596a7cf640eae5e4085, foo: 'foo bar' }


reading document in coll2
document fetched:
{ _id: 5b0b0596a7cf640eae5e4086,
  foreignKey: { _id: 5b0b0596a7cf640eae5e4085, foo: 'baz' } }

что после использования findOneAndReplace проекция в коллекции coll2 не обновляется.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions