Skip to content

Commit f11bb07

Browse files
committed
made requested changes
1 parent 65c42a3 commit f11bb07

File tree

2 files changed

+27
-60
lines changed

2 files changed

+27
-60
lines changed

lib/model.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,10 @@ Model.prototype.$__version = function(where, delta) {
833833
return;
834834
}
835835

836+
if(key === false) {
837+
return;
838+
}
839+
836840
// updates
837841

838842
// only apply versioning if our versionKey was selected. else

test/model.test.js

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7563,68 +7563,31 @@ describe('Model', function() {
75637563

75647564
});
75657565
it('Using bulkSave should not trigger an error (gh-11071)', async function() {
7566-
7567-
class TestModel {
7568-
static _instance
7569-
_model;
7570-
7571-
/**
7572-
* @private
7573-
*/
7574-
constructor() {}
7575-
7576-
static create() {
7577-
if (this._instance) {return this._instance;}
7578-
this._instance = new this();
7579-
7580-
let pairSchema = mongoose.Schema({
7581-
name: String,
7582-
timestamp: String
7583-
}, { versionKey: false });
7584-
7585-
this._instance._model = db.model('test', pairSchema);
7586-
7587-
return this._instance;
7588-
}
75897566

7590-
async insertTests() {
7591-
7592-
const tests = [
7593-
{name: 't1', timestamp: Date.now()},
7594-
{name: 't2', timestamp: Date.now()},
7595-
{name: 't3', timestamp: Date.now()},
7596-
{name: 't4', timestamp: Date.now()},
7597-
];
7598-
7599-
try {
7600-
return this._model.insertMany(tests, {
7601-
ordered: false
7602-
});
7603-
}
7604-
catch (err) {
7605-
throw new Error(`${this.constructor.name} insertMany: ${err}`);
7606-
}
7607-
}
7567+
const pairSchema = mongoose.Schema({
7568+
name: String,
7569+
timestamp: String
7570+
}, { versionKey: false });
76087571

7609-
async all() {
7610-
return await this._model.find({});
7611-
}
7612-
7613-
async bulkSaveTest(tests) {
7614-
for (let p of tests) {
7615-
p.timestamp = Date.now();
7616-
}
7617-
7618-
// !!! "TypeError: path.indexOf is not a function" occurs here
7619-
let res = await this._model.bulkSave(tests);
7620-
return res;
7621-
}
7622-
7623-
}
7624-
const testModel = TestModel.create();
7625-
await testModel.insertTests();
7626-
let tests = await testModel.all();
7627-
assert.ok(await testModel.bulkSaveTest(tests));
7572+
const model = db.model('test', pairSchema);
7573+
const tests = [
7574+
{ name: 't1', timestamp: Date.now() },
7575+
{ name: 't2', timestamp: Date.now() },
7576+
{ name: 't3', timestamp: Date.now() },
7577+
{ name: 't4', timestamp: Date.now() },
7578+
];
7579+
7580+
model.insertMany(tests, {
7581+
ordered: false
7582+
});
7583+
const entries = await model.find({});
7584+
for (const p of entries) {
7585+
p.timestamp = Date.now();
7586+
}
7587+
7588+
// !!! "TypeError: path.indexOf is not a function" occurs here
7589+
const res = await model.bulkSave(entries);
7590+
assert.ok(res);
76287591
});
76297592
});
76307593

0 commit comments

Comments
 (0)