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

Most upvoted comments

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:

new Schema({ arr: [String] }, { usePushEach: true });

@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 },

films: {
    type: [String],
    default: []
}

})

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:

new Schema({ ... }, { usePushEach: true });

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.