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

Replace deprecated mongodb $pushAll operator with $push + $each #4455

Closed
pekebuda opened this issue Aug 24, 2016 · 13 comments
Closed

Replace deprecated mongodb $pushAll operator with $push + $each #4455

pekebuda opened this issue Aug 24, 2016 · 13 comments
Milestone

Comments

@pekebuda
Copy link

According to MongoDB documentation $pushAll has been deprecated since version 2.4. However, it remains the operator Array#push translates into.

On the assumption that is not a breaking change, I think it would be a convenient fix, since some implementation may not rely on $pushAll. In fact, for what it is worth, Azure's own MongoDB implementation does not support $pushAll operator AFAIK .

@vkarpov15 vkarpov15 added this to the 4.6.3 milestone Aug 27, 2016
@vkarpov15
Copy link
Collaborator

Getting off of pushAll is definitely a priority, but fair warning, mongoose does not support documentdb at the moment, so use it at your own risk

@lamuertepeluda
Copy link

This may mitigate the impact of Array.push relying on $pushAll. I tried it myself and seems to work.

myArray.push(myObject); //breaks on DocumentDB with Mongo API because of $pushAll

instead use

myArray = myArray.concat([myObject]); //this uses $set so no problems

@vkarpov15 Supporting DocumentDB with Mongo Protocol (so not DocumentDB as it is) would be fantastic, even though I can understand that project priorities are on Mongo. Sadly Microsoft seem to have implemented just a fair subset of the latest Mongo API (3.x), so deprecated stuff that comes from 2.x may not work.

@vkarpov15 vkarpov15 modified the milestones: 4.6.4, 4.6.3 Oct 6, 2016
vkarpov15 added a commit that referenced this issue Oct 8, 2016
@vkarpov15
Copy link
Collaborator

In 4.6.4 you'll be able to use the usePushEach option in schemas: new Schema({ arr: [String] }, { usePushEach: true });

@knutole
Copy link

knutole commented Dec 8, 2017

Started running into this problem on Mongo 3.6 and Mongoose 4.13.6, message: 'Unknown modifier: $pushAll',

Suggested fix does not work:

var layerSchema = mongoose.Schema({
   (...) 
}, 
{ 
    usePushEach: true 
});

It's weird that this is still an issue with the updated libs?

@frguthmann
Copy link

Same as Knutole here, I'm creating models with mongoose and I don't know if / where I can plugin that fix.

@jrrcdev
Copy link

jrrcdev commented Dec 8, 2017

This suggestion solve the problem in mongodb 3.6 for me.

Edit 1:
Forget, it didn't work here too.

Edit 2:
The solution was keep running on mongo 3.4

@silveur
Copy link

silveur commented Dec 11, 2017

Same issue here using Mongo 3.6
Any push and save on array field generate the error: Unknown modifier: $pushAll
Using the latest Mongoose too...

@pakastin
Copy link

Workaround usePushEach: true seems to work for us. MongoDB 3.6 + db.adminCommand({ setFeatureCompatibilityVersion: "3.6" })

@grantgeorge
Copy link

@knutole what issue are you running into? This solution has worked for me. @frguthmann safest bet would be to add that line to all models if you're using MongoDB 3.6+.

@grantgeorge
Copy link

Mongo 3.6 was recently released and removed support for $pushAll, so everyone downloading the latest and greatest mongo will run into this.

The solution here is to either

  1. Use MongoDB V3.4.X (or 3.5 for that matter, but it's an unstable dev release)

OR

  1. add usePushEach: true option to your models that will require this functionality.

I recommend #1 for production apps.

@shagunchauhan96
Copy link

@knutole That solution worked fine for me. Using v3.6

var aSchema = new mongoose.Schema({
    ...
}, {
        usePushEach: true 
    }
);

Gives no errors.

@vkarpov15
Copy link
Collaborator

There's a fix for this in the upcoming 5.0.0-rc0 release, for now just use the usePushEach option.

@larsdecker
Copy link

Fix works in the 5.0.0-rc2 release.

@Automattic Automattic locked as resolved and limited conversation to collaborators Jan 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests