Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Неправильно обрабатывается обновление первичного ключа #7

Open
lbeschastny opened this issue May 27, 2018 · 0 comments

Comments

@lbeschastny
Copy link
Contributor

Если в качестве первечного ключа (параметр key) использовать не _id, то этот первичный ключ может быть изменен.
Сейчас mongodbext-relations обрабатывает такие обновелния не корректно.

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

Команда для запуска примера:

git clone [email protected]:6aa6ce643c4d7edd0d02f8eb582e0a3c.git && cd 6aa6ce643c4d7edd0d02f8eb582e0a3c && npm i && node .

В примере в качестве первичного ключа используется поле foo:

      foreignKey: {
        collection: coll1,
        key: 'foo',
        projection: { _id: 1, foo: 1 }
      }

При этом при попытке обновить поле foo в документе в коллекции coll1 кидается ошибка

Document with foo=... is not found in `coll1` collection

При этом обновление документа в коллекции coll1 на самом деле происходит, ошибка же возникает при попытке обновить его проекцию в коллекции coll2.
Соответственно, это все приводит к нарушению целостности базы, т.к. в coll1 поле обновилось, а во всех проекциях в coll2 - нет.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant