-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(db): move db constants to other file to avoid circular ref (#1858)
* fix(db): move db constants to other file to avoid circular ref lib/db.js referenced lib/operations/db_ops.js, which in turn referenced lib/db.js to get some constants. Moved constants to their own file, and used dynamic imports to get DB constructor Fixes NODE-1692
- Loading branch information
1 parent
c9996fb
commit 239036f
Showing
4 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
SYSTEM_NAMESPACE_COLLECTION: 'system.namespaces', | ||
SYSTEM_INDEX_COLLECTION: 'system.indexes', | ||
SYSTEM_PROFILE_COLLECTION: 'system.profile', | ||
SYSTEM_USER_COLLECTION: 'system.users', | ||
SYSTEM_COMMAND_COLLECTION: '$cmd', | ||
SYSTEM_JS_COLLECTION: 'system.js' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const mock = require('mongodb-mock-server'); | ||
|
||
describe('CreateIndexError', function() { | ||
const test = {}; | ||
beforeEach(() => mock.createServer().then(_server => (test.server = _server))); | ||
afterEach(() => mock.cleanup()); | ||
|
||
it('should error when createIndex fails', function(done) { | ||
const ERROR_RESPONSE = { | ||
ok: 0, | ||
errmsg: | ||
'WiredTigerIndex::insert: key too large to index, failing 1470 { : "56f37cb8e4b089e98d52ab0e", : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." }', | ||
code: 17280 | ||
}; | ||
|
||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
|
||
if (doc.ismaster) { | ||
return request.reply(Object.assign({}, mock.DEFAULT_ISMASTER)); | ||
} | ||
|
||
if (doc.createIndexes) { | ||
return request.reply(ERROR_RESPONSE); | ||
} | ||
|
||
if (doc.insert === 'system.indexes') { | ||
return request.reply(ERROR_RESPONSE); | ||
} | ||
}); | ||
|
||
const client = this.configuration.newClient(`mongodb://${test.server.uri()}`); | ||
|
||
const close = e => client.close().then(() => done(e)); | ||
|
||
client | ||
.connect() | ||
.then(() => client.db('foo').collection('bar')) | ||
.then(coll => coll.createIndex({ a: 1 })) | ||
.then( | ||
() => close('Expected createIndex to fail, but it succeeded'), | ||
e => { | ||
try { | ||
expect(e).to.have.property('ok', ERROR_RESPONSE.ok); | ||
expect(e).to.have.property('errmsg', ERROR_RESPONSE.errmsg); | ||
expect(e).to.have.property('code', ERROR_RESPONSE.code); | ||
close(); | ||
} catch (err) { | ||
close(err); | ||
} | ||
} | ||
); | ||
}); | ||
}); |