mongoose: Saving a model fails with mongo error: MongoError: Unknown modifier: $pushAll
Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
Test passing on local machine but failing on jenkins server with the exact same versions. The only difference is local is macos and jenkins is ubuntu as far as I can tell.
On MacOS Sierra, node 8.4 and 7.11, mongodb 3.4.7, and mongoose 4.11.7 the following test passes, but on our jenkins server with the exact same versions on an ubuntu 16.04 server fails.
it("should successfully allow an alias that matches a service", async () => {
const aliasTag = "this is a test";
const appAlias = await AliasController.create(user, appAliasSpec);
const serviceAlias = await AliasController.create(user, serviceAliasSpec);
appAlias.aliases.push(aliasTag);
await appAlias.save(); // This is the line that fails in jenkins
serviceAlias.aliases.push(aliasTag);
await serviceAlias.save();
const confAppAlias = await AliasController.getById(appAlias._id);
const confServiceAlias = await AliasController.getById(serviceAlias._id);
expect(confAppAlias.aliases[1]).to.equal(aliasTag);
expect(confServiceAlias.aliases[1]).to.equal(aliasTag);
});
Here is the exact error that i’m getting:
{
"message": "Unknown modifier: $pushAll",
"name": "MongoError",
"stack": "MongoError: Unknown modifier: $pushAll\n at Function.MongoError.create (/var/lib/jenkins/workspace/davis-cloudcontrol/node_modules/mongodb-core/lib/error.js:31:11)\n at toError (/var/lib/jenkins/workspace/davis-cloudcontrol/node_modules/mongodb/lib/utils.js:139:22)\n at /var/lib/jenkins/workspace/davis-cloudcontrol/node_modules/mongodb/lib/collection.js:1060:67\n at /var/lib/jenkins/workspace/davis-cloudcontrol/node_modules/mongodb-core/lib/connection/pool.js:469:18\n at _combinedTickCallback (internal/process/next_tick.js:131:7)\n at process._tickCallback (internal/process/next_tick.js:180:9)",
"code": 9
}
edit: Here is a more readable version of the stack trace
MongoError: Unknown modifier: $pushAll
at Function.MongoError.create (/var/lib/jenkins/workspace/davis-cloudcontrol/node_modules/mongodb-core/lib/error.js:31:11)
at toError (/var/lib/jenkins/workspace/davis-cloudcontrol/node_modules/mongodb/lib/utils.js:139:22)
at /var/lib/jenkins/workspace/davis-cloudcontrol/node_modules/mongodb/lib/collection.js:1060:67
at /var/lib/jenkins/workspace/davis-cloudcontrol/node_modules/mongodb-core/lib/connection/pool.js:469:18
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 27 (1 by maintainers)
Commits related to this issue
- Add `usePushEach` flag to Mongoose Schema Options (#23042) In order for devs to be able to work around the issues described in https://github.com/Automattic/mongoose/issues/5574 we need to be able ... — committed to DefinitelyTyped/DefinitelyTyped by stieg 6 years ago
- Updates in song model. Was getting this error while adding the lyrics. Issue and patch mentioned here https://github.com/Automattic/mongoose/issues/5574#issuecomment-361657962 ```bundle.js:6882 Un... — committed to theparadoxer02/Lyrical-GraphQL by theparadoxer02 6 years ago
- Fix https://github.com/Automattic/mongoose/issues/5574 , add nodemon and improve readme — committed to jrichardsz/attendance-system by jrichardsz 6 years ago
- fix user registration https://github.com/Automattic/mongoose/issues/5574 — committed to coach-plus/server by Finkes 5 years ago
Well that’s one problem, mongodb 3.5 is an unstable dev release and should not be used. $pushAll has been deprecated for a long time so perhaps they got rid of it in 3.5. @mbroadst can you clarify?
We added a
usePushEach
option to work around this a while back: https://github.com/Automattic/mongoose/issues/4455 , that should be a workaround for this issue:@vkarpov15 Thanks for the fantastic library sir.
I, too, anm experiencing this issue with Mongoose 4.13.7 and MongoDB 3.6.0.
UPDATE: Adding
usePushEach: true
to schema options for models resolved this.Пробовал вот так не работает const mongoose = require (‘mongoose’) const Схема = mongoose.Schema
const UserSchema = new Schema ({ telegramId: { type: Number, required: true, usePushEach: true },
films: { type: [String], default: [] } })
mongoose.model (‘users’, UserSchema)
Всем привет, подскажите пожалуйста как исправить ошибку Неизвестный модификатор: $ pushAll
Как то вот так const mongoose = require(‘mongoose’) const Schema = mongoose.Schema
const UserSchema = new Schema({ telegramId: { type: Number, required: true },
})
new Schema({}, {usePushEach: true})
mongoose.model(‘users’, UserSchema)
@rivers-lis You have to add
usePushEach
to the schema options, not to the schema, like so:Mongoose 5 should not be affected by this issue, it doesn’t use
$pushAll
anywhere. If you get this error with mongoose 5, please open up an issue with code samples 👍@rankitbishnoi You can get around this temporarily by adding the
usePushEach
option on each schema definition in the options.Updating the schema does not change this behavior. It’s not working for older data in the database already for 3.6.
Edit: Reverting back to version 3.4 solved the problem.