Solvedmongoose 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)
28 Answers

✔️Accepted Answer

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: #4455 , that should be a workaround for this issue:

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

Other Answers:

@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.

@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.

Related Issues:

360
mongoose Deprecation Warning
I solved that warning doing Right before calling mongoose.connect I'm getting this warning after I d...
119
mongoose Saving a model fails with mongo error: MongoError: Unknown modifier: $pushAll
Well that's one problem mongodb 3.5 is an unstable dev release and should not be used ...
69
mongoose Is not a function ERROR - this.isModified is not a function
You are using an arrow operator for the callback which changes the scope of this If you define a reg...
39
mongoose No retries are made after "failed to connect on first connect"
For anyone wanting auto-reconnection when first connect fails By default mongoose throws an Error if...
34
mongoose Need to check if password field has been modified in pre findOneAndUpdate
I'm currently using this solution and it works You don't need to execute another query. ...
28
mongoose Allow import { model } from mongoose
+1 Currently this doesn't work: It's common when user wants to import variables from module without ...
21
mongoose the options [user] and [pass] is not supported when using with useMongoClient: true
Working on getting support for this in the mongodb driver with the above PR ☝️ For now as a workarou...
19
mongoose Property 'Buffer' does not exist on type 'typeof globalThis'.
Think explicitly adding @types/node should work as a temp workaround npm i --save-dev @types/node@^1...
18
mongoose server/replset/mongos options are deprecated => documentation?
The message says that all of the server replset and mongos options have been moved to the top level ...
12
mongoose Way to handle mongoose.connect() error in promise catch handler
Use the callback of mongoose.connect to catch any error during the connection You can start you serv...
6
mongoose Handle cast error on find when objectId is invalid
This is expected behavior and your way of handling the error is mostly correct Do you want to reques...
5
mongoose mongoose 5.4.20 does not overwrite all properties in a nested subdocument.
I have the same problem using Object.assign() Do you want to request a feature or report a bug? Bug ...