Skip to content

Commit 79c8a35

Browse files
committed
static sync indexes
1 parent 77f8487 commit 79c8a35

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/drivers/node-mongodb-native/connection.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ NativeConnection.prototype.doClose = function(force, fn) {
146146
return this;
147147
};
148148

149+
/*
150+
NativeConnection.prototype.syncIndexes = function() {
151+
console.log(this);
152+
}*/
153+
149154
/*!
150155
* Module exports.
151156
*/

test/connection.test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,32 @@ describe('connections:', function() {
10791079
assert.deepStrictEqual(conn3.id, m.connection.id + 2);
10801080
});
10811081

1082-
it('Allows a syncIndexes option (gh-10893)', async function() {
1082+
it('Allows a syncIndexes option with connection mongoose.connection.syncIndexes (gh-10893)', async function() {
1083+
this.timeout(10000);
1084+
1085+
1086+
const coll = 'tests2';
10831087
const m = new mongoose.Mongoose();
10841088
const conn = m.createConnection('mongodb://localhost:27017');
1085-
conn.model('Test', new Schema({name: {type: String, index: true}}));
1089+
let M = conn.model('Test', new Schema({name: {type: String, index: true}}, {autoIndex: false}), coll);
10861090
const sync = await conn.syncIndexes();
10871091
assert(sync, [[]] );
1092+
let indexes = await M.listIndexes();
1093+
assert.deepEqual(indexes.map(i => i.key), [
1094+
{ _id: 1 },
1095+
{ name: 1 }
1096+
]);
1097+
conn.deleteModel(/Test/);
1098+
M = conn.model('Test', new Schema({
1099+
otherName: { type: String, index: true }
1100+
}, { autoIndex: false }), coll);
1101+
const dropped = await conn.syncIndexes();
1102+
assert.deepEqual(dropped, [['name_1']]);
1103+
await M.collection.drop();
1104+
});
1105+
it('Allows a syncIndexes shorthand mongoose.syncIndexes (gh-10893)', async function () {
1106+
// const m = new mongoose.Mongoose();
1107+
// console.log(m.syncIndexes());
1108+
assert(true, true)
10881109
});
10891110
});

0 commit comments

Comments
 (0)