Skip to content
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

Saving a model fails with mongo error: MongoError: Unknown modifier: $pushAll #5574

Closed
dyladan opened this issue Aug 23, 2017 · 27 comments
Closed
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity

Comments

@dyladan
Copy link

dyladan commented Aug 23, 2017

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)
@sobafuchs
Copy link
Contributor

can you do mongoose.set('debug', true) and paste the mongo output?

@sobafuchs sobafuchs added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Aug 23, 2017
@dyladan
Copy link
Author

dyladan commented Aug 23, 2017

edit: more clear output

Mongoose: aliases.update({ _id: ObjectId("599d98122b72d12e0ba858b4") }, { '$pushAll': { aliases: [ 'this is a test' ] }, '$set': { updatedAt: new Date("Wed, 23 Aug 2017 14:58:26 GMT") }, '$inc': { __v: 1 } })
{"name":"davis","hostname":"ld-ub-bm980a98v","pid":11787,"level":50,"err":{"message":"Unknown modifier: $pushAll","name":"MongoError","stack":"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)","code":9},"msg":"An unhandled Mongo error occurred.","time":"2017-08-23T14:58:26.201Z","v":0}

@dyladan
Copy link
Author

dyladan commented Aug 23, 2017

For what it's worth, I checked the debug output in our local development and production environments and they're both using the $pushAll modifier successfully. Mongo is installed from the official packages in all cases. Development machines are windows and MacOS, production machines are amazon linux.

@vkarpov15
Copy link
Collaborator

Can you connect to your jenkins mongodb instance using the mongo shell and double check the version using db.version?

$ mongo test
MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017/test
MongoDB server version: 3.4.1 
> db.version()
3.4.1
> ^C
bye

You can also print the server version out using the serverStatus() command using mongoose:

const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/test');

mongoose.connection.on('open', function() {
  mongoose.connection.db.admin().serverStatus(function(error, info) {
    console.log(info.version);
  });
});

Please double check your version first, official packages tend to fall out of date pretty quickly.

@Spown
Copy link

Spown commented Sep 21, 2017

yep, have the same error. tried to move from 3.2 to 3.5 (no data migration). I have an array field

    'liked': {
        'item':[ {
            'id': {'type': Types.ObjectId, 'ref': 'Item'},
            'score': {'type': Number, 'max': 100, 'default': -1},
            'comment': {'type': String, 'maxlength': 65000, 'trim': true, 'default': '', 'set': san.methods.safe}
        } ]
    },

I know, id is not the best field name, but hey, it worked in 3.2. In 3.5 it fails after trying to .save() the doc after an Item been pushed into the array. I push the items via .push() and then mark the field .markModified('liked.item');. schould be simple.

@vkarpov15
Copy link
Collaborator

MongoDB 3.5?

@Spown
Copy link

Spown commented Sep 26, 2017

yes

 targetMinOS: Windows 7/Windows Server 2008 R2
 db version v3.5.13
 git version: 52bbaa007cd84631d6da811d9a05b59f2dfad4f3
 OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
 allocator: tcmalloc
 modules: none
 build environment:
     distmod: 2008plus-ssl
     distarch: x86_64
     target_arch: x86_64

@vkarpov15
Copy link
Collaborator

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 });

@mbroadst
Copy link

@vkarpov15 yes it's been removed for featureCompatibilityVersion=3.6

@vkarpov15
Copy link
Collaborator

Touche. In which case we'll make sure to get #5670 out.

@rankitbishnoi
Copy link

i am having the same exact problem i am using mongodb v3.6 on my ubuntu. if the pushAll is removed from db than how should i save the instance.. please provide me any alternative

@dyladan
Copy link
Author

dyladan commented Dec 20, 2017

@rankitbishnoi You can get around this temporarily by adding the usePushEach option on each schema definition in the options.

@chaddjohnson
Copy link

chaddjohnson commented Dec 20, 2017

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

@rod-stuchi
Copy link

@dyladan @chaddjohnson really works.
thanks a lot!

@raphaelbp12
Copy link

please, how can I do this? how can I add this to schema options? thank you!

@chaddjohnson
Copy link

@raphaelbp12 Here are the docs on using schema options: http://mongoosejs.com/docs/guide.html

@danieltanfh95
Copy link

danieltanfh95 commented Dec 31, 2017

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.

@frederico-alves
Copy link

frederico-alves commented Dec 31, 2017

I was having a similar issue running the code in my machine. I think is because of Mongoose 5 and MongoDB 3.6. Try to revert back:

  • Mongoose to version 4.13.8 (npm install mongoose@4.13.8 --save), and
  • MongoDB to 3.4 (you can check the version typing db.version() ).

It worked for me! :)

@vkarpov15
Copy link
Collaborator

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 👍

weswigham pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this issue Jan 19, 2018
In order for devs to be able to work around the issues described in
Automattic/mongoose#5574 we need to be able
to supply the `usePushEach` flag to the Mongoose SchemaOptions. This
options functionality is described in
Automattic/mongoose#4455 and is required for
anyone who modifies arrays inline who is using Mongoose 4 and MongoDB
3.6+

Testing:
  Copied changes to local project and verified compilation worked.
@JoseRFJuniorLLMs
Copy link

PS C:\Users\paula\projetos\apiNode\src> node index.js
{ MongoError: Unknown modifier: $pushAll
at Function.MongoError.create (C:\Users\paula\projetos\apiNode\node_modules\mongodb-core\lib\error.js:31:11)
at toError (C:\Users\paula\projetos\apiNode\node_modules\mongodb\lib\utils.js:139:22)
at C:\Users\paula\projetos\apiNode\node_modules\mongodb\lib\collection.js:1059:67
at C:\Users\paula\projetos\apiNode\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)
name: 'MongoError',
message: 'Unknown modifier: $pushAll',
driver: true,
index: 0,
code: 9

@rivers-lis
Copy link

Всем привет, подскажите пожалуйста как исправить ошибку Неизвестный модификатор: $ pushAll

@rivers-lis
Copy link

Пробовал вот так не работает
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)

@chaddjohnson
Copy link

@rivers-lis You have to add usePushEach to the schema options, not to the schema, like so:

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

@rivers-lis
Copy link

Как то вот так
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)

@ankit-chheda
Copy link

new Schema({ ... }, { usePushEach: true });
This solves the error for me too on version 4.4.12 and 5.0.7

theparadoxer02 added a commit to theparadoxer02/Lyrical-GraphQL that referenced this issue Sep 20, 2018
Was getting this error while adding the lyrics. Issue and patch mentioned here Automattic/mongoose#5574 (comment)

```bundle.js:6882 Uncaught (in promise) Error: GraphQL error: Unknown modifier: $pushAll
    at new ApolloError (bundle.js:6885)
    at bundle.js:15869```
jrichardsz added a commit to jrichardsz/attendance-system that referenced this issue Nov 10, 2018
@DanGDroid
Copy link

Как то вот так
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)

sorry cannot read Russian

@vkarpov15
Copy link
Collaborator

@DanGDroid roughly translated "Как то вот так" -> "Something like this"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
Projects
None yet
Development

No branches or pull requests