-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
bulkSave bug: "TypeError: path.indexOf is not a function" #11071
Comments
const mongoose = require('mongoose');
let pairSchema = new mongoose.Schema({
ask: Number,
bid: Number,
last: Number,
code: String
}, { versionKey: false });
const model = mongoose.model('pairs', pairSchema);
async function test() {
await mongoose.connect('mongodb://localhost:27017/', {useNewUrlParser: true,
useUnifiedTopology: true,});
await mongoose.connection.dropDatabase();
let pairs = await model.find({});
// modify all documents
for (let p of pairs) {
p.code = "test"
}
// !!! "TypeError: path.indexOf is not a function" occurs here
let res = await model.bulkSave(pairs);
console.log('done');
}
test(); |
same version of mongoose, v 16 of node |
@IslandRhythms Please try our new test without File TestModel.js
File app.js
|
Could you please add it also to TS types when fixed ? |
@shyrik13 because if I don't then the modifications from the previous run are still there. When you gave the script you did not indicate that it needed to be ran twice to show an error. Are you saying that now? |
@IslandRhythms I see, then yes. Script from #11071 (comment) should help to reproduce mentioned error. |
I ran the initial script four times with the 'use strict';
const mongoose = require('mongoose');
/**
* @singleton - use create method to get instance.
* Mongoose model can't be compiled multiple times, therefor singleton is used.
*/
class TestModel {
static _instance;
_model;
/**
* @private
*/
constructor() {}
static create() {
if (this._instance) {return this._instance;}
this._instance = new this();
let pairSchema = new mongoose.Schema({
name: String,
timestamp: String
}, { versionKey: false });
this._instance._model = mongoose.model('test', pairSchema);
return this._instance;
}
async insertTests() {
const tests = [
{name: 't1', timestamp: Date.now()},
{name: 't2', timestamp: Date.now()},
{name: 't3', timestamp: Date.now()},
{name: 't4', timestamp: Date.now()},
];
try {
return this._model.insertMany(tests, {
ordered: false
});
}
catch (err) {
throw new Error(`${this.constructor.name} insertMany: ${err}`);
}
}
async all() {
return await this._model.find({});
}
async bulkSaveTest(tests) {
for (let p of tests) {
p.timestamp = Date.now();
}
// !!! "TypeError: path.indexOf is not a function" occurs here
let res = await this._model.bulkSave(tests);
console.log('saved');
}
}
const testModel = TestModel.create();
async function test() {
await mongoose.connect('mongodb://localhost:27017/', {useNewUrlParser: true,
useUnifiedTopology: true,});
await mongoose.connection.dropDatabase();
await testModel.insertTests();
let tests = await testModel.all();
await testModel.bulkSaveTest(tests);
}
test(); |
Report a bug
Current behavior
Using bulkSave method returns such error after
Documents
modified:Steps to reproduce.
Expected behavior
Takes an array of documents, gets the changes and inserts/updates documents in the database according to whether or not the document is new, or whether it has changes or not.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS: v13.14.0
Mongoose: ^6.1.1
MongoDB: Docker image: mongo:4.2
The text was updated successfully, but these errors were encountered: