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)
can you do mongoose.set('debug', true)
and paste the mongo output?
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}
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.
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.
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.
MongoDB 3.5?
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
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 yes it's been removed for featureCompatibilityVersion=3.6
Touche. In which case we'll make sure to get #5670 out.
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
@rankitbishnoi You can get around this temporarily by adding the usePushEach
option on each schema definition in the options.
@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.
@dyladan @chaddjohnson really works.
thanks a lot!
please, how can I do this? how can I add this to schema options? thank you!
@raphaelbp12 Here are the docs on using schema options: http://mongoosejs.com/docs/guide.html
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.
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:
npm install [email protected] --save
), anddb.version()
).It worked for me! :)
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 :+1:
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
ΠΡΠ΅ΠΌ ΠΏΡΠΈΠ²Π΅Ρ, ΠΏΠΎΠ΄ΡΠΊΠ°ΠΆΠΈΡΠ΅ ΠΏΠΎΠΆΠ°Π»ΡΠΉΡΡΠ° ΠΊΠ°ΠΊ ΠΈΡΠΏΡΠ°Π²ΠΈΡΡ ΠΎΡΠΈΠ±ΠΊΡ ΠΠ΅ΠΈΠ·Π²Π΅ΡΡΠ½ΡΠΉ ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡ: $ pushAll
ΠΡΠΎΠ±ΠΎΠ²Π°Π» Π²ΠΎΡ ΡΠ°ΠΊ Π½Π΅ ΡΠ°Π±ΠΎΡΠ°Π΅Ρ
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)
@rivers-lis You have to add usePushEach
to the schema options, not to the schema, like so:
new Schema({ ... }, { usePushEach: true });
ΠΠ°ΠΊ ΡΠΎ Π²ΠΎΡ ΡΠ°ΠΊ
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)
new Schema({ ... }, { usePushEach: true });
This solves the error for me too on version 4.4.12 and 5.0.7
ΠΠ°ΠΊ ΡΠΎ Π²ΠΎΡ ΡΠ°ΠΊ
const mongoose = require('mongoose')
const Schema = mongoose.Schemaconst UserSchema = new Schema({
telegramId: {
type: Number,
required: true
},films: { type: [String], default: [] }
})
new Schema({}, {usePushEach: true})
mongoose.model('users', UserSchema)
sorry cannot read Russian
@DanGDroid roughly translated "ΠΠ°ΠΊ ΡΠΎ Π²ΠΎΡ ΡΠ°ΠΊ" -> "Something like this"
Most helpful comment
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: