Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Web Technology by (50.2k points)

While saving a model, I am getting the following mongo error: 

MongoError: Unknown modifier: $pushAll.

I am having one array field subDomains in my data structure, refer the following code:

 // already Domain instance get availble 

 Domain.subDomains.push({'name': 'default' , 'role': 'xyz', ...});

 // save domain with default fileds

 Domain.save() 

The system information is 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

          ➜  ~ 

Where I am not able to save the model?

1 Answer

0 votes
by (107k points)
edited by

The newer versions of MongoDB that are from MongoDB 3.6.x+, $pushAll is not supported. Instead of using $pushAll, you can set usePushEach as a true option in the schema definition.

Or you can also use the concat method: 

Instead of writing: 

Domain.subDomains.push({'name': 'default' , 'role': 'xyz', ...});

Write:

subDomains=subDomain.concat([{'name': 'default' , 'role': 'xyz', ...}]);

 Do you want to be a full-stack developer? Enroll in this Full Stack Certification to get started with your journey.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...