Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoError: Unknown modifier: $pushAll in node js

I am having an issue when saving a model fails with mongo error: MongoError: Unknown modifier: $pushAll.

I have one array field subDomains in my schema and which will get saved as default with subdomain as like follows.

 // already Domain instance get availble 
 Domain.subDomains.push({'name': 'default' , 'role': 'xyz', ...});

 // save domain with default fileds
 Domain.save() 

System Info as like as follows:

         ➜  ~ node --version
          v9.4.0
          ➜  ~ npm --version
          5.6.0
          ➜  ~ 
          ➜  ~ mongo --version
            MongoDB shell version v3.6.2
            git version: ......
            OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
            allocator: system
            modules: none
            build environment:
                distarch: x86_64
                target_arch: x86_64
          ➜  ~ 

Please help me to sort out this one.

like image 776
Santosh Shinde Avatar asked Sep 06 '25 13:09

Santosh Shinde


1 Answers

The $pushAll operator is no longer supported in Mongo 3.6.2 (or any newer versions from 3.6.x+).

You can do the following:

  • add the usePushEach: true option the Schema definition as in:

    new mongoose.Schema({
      username: String
    }, {
      usePushEach: true
    });
    
  • downgrade to Mongo 3.4.11(or any 3.4.x version)

like image 92
Teodor Kurtev Avatar answered Sep 09 '25 22:09

Teodor Kurtev