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

Duplicate key error when using change tracking. #649

Closed
BerkeleyTrue opened this issue Oct 15, 2014 · 4 comments
Closed

Duplicate key error when using change tracking. #649

BerkeleyTrue opened this issue Oct 15, 2014 · 4 comments
Assignees
Labels

Comments

@BerkeleyTrue
Copy link
Contributor

Using loopback 2.4.1
When using change tracking and creating a new instance of a model. A new model is created and a change model instance is also created, then the server crashes with the following.

Error: MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: changeDuplicateKey.mat-change.$_id_  dup key: { : "a79d721d7491273e0fc6c5d8b900e5ffca9296cd" }
    at cb (/Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback/lib/models/change.js:170:19)
    at /Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-datasource-juggler/lib/dao.js:230:20
    at /Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-connector-mongodb/lib/mongodb.js:204:14
    at /Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongodb/collection/core.js:120:18
    at /Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongodb/db.js:1183:7
    at /Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongodb/db.js:1916:9
    at Server.Base._callHandler (/Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongodb/connection/base.js:448:41)
    at /Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongodb/connection/server.js:481:18
    at MongoReply.parseBody (/Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    at null.<anonymous> (/Users/berkeley/node/loopback/changeDuplicateKey/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongodb/connection/server.js:439:20)

This duplicate key problem also occurs when using the postgresql connector.
I created a repo that replicates the issue here.

@BerkeleyTrue
Copy link
Contributor Author

Switching models to the memory connector does not cause this problem. Any ideas why this is happening?

@bajtos
Copy link
Member

bajtos commented Oct 16, 2014

@ritch you know most about the replication algo, could you please investigate?

@BerkeleyTrue
Copy link
Contributor Author

see pull request. #668

@bajtos
Copy link
Member

bajtos commented Nov 13, 2014

Fixed by #668. A new version will be released in next few days.

@bajtos bajtos closed this as completed Nov 13, 2014
raymondfeng pushed a commit that referenced this issue Nov 19, 2014
2.8.0

 * Expose more loopback middleware for require (Raymond Feng)

 * Scope app middleware to a list of paths (Miroslav Bajtoš)

 * Update CONTRIBUTING.md (Alex Voitau)

 * Fix the model name for hasMany/through relation (Raymond Feng)

 * Fixing the model attach (wfgomes)

 * Minor: update jsdoc for PersistedModel.updateAll (Alex Voitau)

 * AccessToken: optional `options` in findForRequest (Miroslav Bajtoš)

 * server-app: improve jsdoc comments (Miroslav Bajtoš)

 * server-app: middleware API improvements (Miroslav Bajtoš)

 * typo of port server (wfgomes)

 * Move middleware sources to `server/middleware` (Miroslav Bajtoš)

 * app.middleware: verify serial exec of handlers (Miroslav Bajtoš)

 * Simplify `app.defineMiddlewarePhases` (Miroslav Bajtoš)

 * Make sure loopback has all properties from express (Raymond Feng)

 * Implement `app.defineMiddlewarePhases` (Miroslav Bajtoš)

 * Implement app.middlewareFromConfig (Miroslav Bajtoš)

 * middleware/token: store the token in current ctx (Miroslav Bajtoš)

 * Fix `loopback.getCurrentContext` (Miroslav Bajtoš)

 * Update chai to ^1.10.0 (Miroslav Bajtoš)

 * package: fix deps (Miroslav Bajtoš)

 * Middleware phases - initial implementation (Miroslav Bajtoš)

 * Allows ACLs/settings in model config (Raymond Feng)

 * Remove context middleware per Ritchie (Rand McKinney)

 * Add API doc for context middleware - see #337 (crandmck)

 * Update persisted-model.js (Rand McKinney)

 * rest middleware: clean up context config (Miroslav Bajtoš)

 * Move `context` example to a standalone app (Miroslav Bajtoš)

 * Enable the context middleware from loopback.rest (Raymond Feng)

 * Add context propagation middleware (Raymond Feng)

 * Changes to JSdoc comments (Rand McKinney)

 * Reorder classes alphabetically in each section (Rand McKinney)

 * common: coding style cleanup (Miroslav Bajtoš)

 * Coding style cleanup (Gruntfile, lib) (Miroslav Bajtoš)

 * Enable jscs for `lib`, fix style violations (Rob Halff)

 * Add access-context.js to API doc (Rand McKinney)

 * Remove doc for debug function (Rand McKinney)

 * Update registry.js (Rand McKinney)

 * Fix the jsdoc for User.login (Raymond Feng)

 * Deleted instantiation of new Change model. This PR removes the instantiation of a new change model as models return from Change.find are already instances of Change. This solves the duplicate Id issue #649 (Berkeley Martinez)

 * Expose path to the built-in favicon file (Miroslav Bajtoš)

 * Add API docs for `loopback.static`. (Miroslav Bajtoš)

 * Add test for `remoting.rest.supportedTypes` (Miroslav Bajtoš)

 * Revert "rest handler options" (Miroslav Bajtoš)

 * REST handler options. (Guilherme Cirne)

 * The elapsed time in milliseconds can be 0 (less than 1 ms) (Raymond Feng)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants