Error: the update operation document must contain atomic operators, when running updateOne










33















In my collection, there is only one document.



> db.c20160712.find()
{ "_id" : ObjectId("57ab909791c3b3a393e9e277"), "Dimension_id" : 2, "Attribute" : "good", "Hour" : "20160712_06", "Frequency_count" : 100


I want to run updateOne to replace the document with another one. But why is there Error: the update operation document must contain atomic operators?



> db.c20160712.updateOne( "Attribute" : "good", "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action", upsert: true )
2016-08-10T16:37:57.089-0400 E QUERY [thread1] Error: the update operation document must contain atomic operators :
DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:493:1
@(shell):1:1


The second and third arguments in the above command comes from an example in The Definitive Guide to MongoDB: A complete guide to dealing with Big Data ...
By Eelco Plugge, David Hows, Peter Membrey, Tim Hawkins



My MongoDB is 3.2.










share|improve this question




























    33















    In my collection, there is only one document.



    > db.c20160712.find()
    { "_id" : ObjectId("57ab909791c3b3a393e9e277"), "Dimension_id" : 2, "Attribute" : "good", "Hour" : "20160712_06", "Frequency_count" : 100


    I want to run updateOne to replace the document with another one. But why is there Error: the update operation document must contain atomic operators?



    > db.c20160712.updateOne( "Attribute" : "good", "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action", upsert: true )
    2016-08-10T16:37:57.089-0400 E QUERY [thread1] Error: the update operation document must contain atomic operators :
    DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:493:1
    @(shell):1:1


    The second and third arguments in the above command comes from an example in The Definitive Guide to MongoDB: A complete guide to dealing with Big Data ...
    By Eelco Plugge, David Hows, Peter Membrey, Tim Hawkins



    My MongoDB is 3.2.










    share|improve this question


























      33












      33








      33








      In my collection, there is only one document.



      > db.c20160712.find()
      { "_id" : ObjectId("57ab909791c3b3a393e9e277"), "Dimension_id" : 2, "Attribute" : "good", "Hour" : "20160712_06", "Frequency_count" : 100


      I want to run updateOne to replace the document with another one. But why is there Error: the update operation document must contain atomic operators?



      > db.c20160712.updateOne( "Attribute" : "good", "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action", upsert: true )
      2016-08-10T16:37:57.089-0400 E QUERY [thread1] Error: the update operation document must contain atomic operators :
      DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:493:1
      @(shell):1:1


      The second and third arguments in the above command comes from an example in The Definitive Guide to MongoDB: A complete guide to dealing with Big Data ...
      By Eelco Plugge, David Hows, Peter Membrey, Tim Hawkins



      My MongoDB is 3.2.










      share|improve this question
















      In my collection, there is only one document.



      > db.c20160712.find()
      { "_id" : ObjectId("57ab909791c3b3a393e9e277"), "Dimension_id" : 2, "Attribute" : "good", "Hour" : "20160712_06", "Frequency_count" : 100


      I want to run updateOne to replace the document with another one. But why is there Error: the update operation document must contain atomic operators?



      > db.c20160712.updateOne( "Attribute" : "good", "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action", upsert: true )
      2016-08-10T16:37:57.089-0400 E QUERY [thread1] Error: the update operation document must contain atomic operators :
      DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:493:1
      @(shell):1:1


      The second and third arguments in the above command comes from an example in The Definitive Guide to MongoDB: A complete guide to dealing with Big Data ...
      By Eelco Plugge, David Hows, Peter Membrey, Tim Hawkins



      My MongoDB is 3.2.







      mongodb






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 29 '18 at 17:56









      A-Sharabiani

      6,19395384




      6,19395384










      asked Aug 10 '16 at 20:50









      TimTim

      31.4k109246370




      31.4k109246370






















          3 Answers
          3






          active

          oldest

          votes


















          52














          Wrong syntax for the second parameter. Please check the docs. It should be:



          db.c20160712.updateOne(
          "Attribute" : "good" ,
          $set: "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" ,
          upsert: true
          );





          share|improve this answer























          • I am a bit puzzled with "I don't just do update" part. What else you expect from update function?

            – Alex Blex
            Aug 10 '16 at 21:38











          • I want to update an entire matching document.

            – Tim
            Aug 10 '16 at 21:40







          • 2





            You mean "replace" the document? Then you should follow @dyouberg's advice and use correct function.

            – Alex Blex
            Aug 10 '16 at 21:42


















          10














          I believe this was changed as a side-effect of introducing the updateOne method in addition to update() and updateMany() as somewhat of a safeguard to prevent user's from accidentally overriding an entire document.



          You can use the replaceOne() method instead, or an update() without specifying multi:true.






          share|improve this answer






























            2














            You should use this code because I was also facing the same problem and then I used this code:



            updateOne(
            _id: new ObjectID(req.params.id) ,
            $set: title: req.body.bookName, author: req.body.authorName ,
            upsert: true
            )


            and you should also define ObjectID otherwise the problem will occur again....



            const ObjectID = require('mongodb').ObjectID;






            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38883285%2ferror-the-update-operation-document-must-contain-atomic-operators-when-running%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              52














              Wrong syntax for the second parameter. Please check the docs. It should be:



              db.c20160712.updateOne(
              "Attribute" : "good" ,
              $set: "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" ,
              upsert: true
              );





              share|improve this answer























              • I am a bit puzzled with "I don't just do update" part. What else you expect from update function?

                – Alex Blex
                Aug 10 '16 at 21:38











              • I want to update an entire matching document.

                – Tim
                Aug 10 '16 at 21:40







              • 2





                You mean "replace" the document? Then you should follow @dyouberg's advice and use correct function.

                – Alex Blex
                Aug 10 '16 at 21:42















              52














              Wrong syntax for the second parameter. Please check the docs. It should be:



              db.c20160712.updateOne(
              "Attribute" : "good" ,
              $set: "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" ,
              upsert: true
              );





              share|improve this answer























              • I am a bit puzzled with "I don't just do update" part. What else you expect from update function?

                – Alex Blex
                Aug 10 '16 at 21:38











              • I want to update an entire matching document.

                – Tim
                Aug 10 '16 at 21:40







              • 2





                You mean "replace" the document? Then you should follow @dyouberg's advice and use correct function.

                – Alex Blex
                Aug 10 '16 at 21:42













              52












              52








              52







              Wrong syntax for the second parameter. Please check the docs. It should be:



              db.c20160712.updateOne(
              "Attribute" : "good" ,
              $set: "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" ,
              upsert: true
              );





              share|improve this answer













              Wrong syntax for the second parameter. Please check the docs. It should be:



              db.c20160712.updateOne(
              "Attribute" : "good" ,
              $set: "Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" ,
              upsert: true
              );






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 10 '16 at 21:09









              Alex BlexAlex Blex

              16.7k22145




              16.7k22145












              • I am a bit puzzled with "I don't just do update" part. What else you expect from update function?

                – Alex Blex
                Aug 10 '16 at 21:38











              • I want to update an entire matching document.

                – Tim
                Aug 10 '16 at 21:40







              • 2





                You mean "replace" the document? Then you should follow @dyouberg's advice and use correct function.

                – Alex Blex
                Aug 10 '16 at 21:42

















              • I am a bit puzzled with "I don't just do update" part. What else you expect from update function?

                – Alex Blex
                Aug 10 '16 at 21:38











              • I want to update an entire matching document.

                – Tim
                Aug 10 '16 at 21:40







              • 2





                You mean "replace" the document? Then you should follow @dyouberg's advice and use correct function.

                – Alex Blex
                Aug 10 '16 at 21:42
















              I am a bit puzzled with "I don't just do update" part. What else you expect from update function?

              – Alex Blex
              Aug 10 '16 at 21:38





              I am a bit puzzled with "I don't just do update" part. What else you expect from update function?

              – Alex Blex
              Aug 10 '16 at 21:38













              I want to update an entire matching document.

              – Tim
              Aug 10 '16 at 21:40






              I want to update an entire matching document.

              – Tim
              Aug 10 '16 at 21:40





              2




              2





              You mean "replace" the document? Then you should follow @dyouberg's advice and use correct function.

              – Alex Blex
              Aug 10 '16 at 21:42





              You mean "replace" the document? Then you should follow @dyouberg's advice and use correct function.

              – Alex Blex
              Aug 10 '16 at 21:42













              10














              I believe this was changed as a side-effect of introducing the updateOne method in addition to update() and updateMany() as somewhat of a safeguard to prevent user's from accidentally overriding an entire document.



              You can use the replaceOne() method instead, or an update() without specifying multi:true.






              share|improve this answer



























                10














                I believe this was changed as a side-effect of introducing the updateOne method in addition to update() and updateMany() as somewhat of a safeguard to prevent user's from accidentally overriding an entire document.



                You can use the replaceOne() method instead, or an update() without specifying multi:true.






                share|improve this answer

























                  10












                  10








                  10







                  I believe this was changed as a side-effect of introducing the updateOne method in addition to update() and updateMany() as somewhat of a safeguard to prevent user's from accidentally overriding an entire document.



                  You can use the replaceOne() method instead, or an update() without specifying multi:true.






                  share|improve this answer













                  I believe this was changed as a side-effect of introducing the updateOne method in addition to update() and updateMany() as somewhat of a safeguard to prevent user's from accidentally overriding an entire document.



                  You can use the replaceOne() method instead, or an update() without specifying multi:true.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 10 '16 at 21:01









                  dyoubergdyouberg

                  1,061516




                  1,061516





















                      2














                      You should use this code because I was also facing the same problem and then I used this code:



                      updateOne(
                      _id: new ObjectID(req.params.id) ,
                      $set: title: req.body.bookName, author: req.body.authorName ,
                      upsert: true
                      )


                      and you should also define ObjectID otherwise the problem will occur again....



                      const ObjectID = require('mongodb').ObjectID;






                      share|improve this answer





























                        2














                        You should use this code because I was also facing the same problem and then I used this code:



                        updateOne(
                        _id: new ObjectID(req.params.id) ,
                        $set: title: req.body.bookName, author: req.body.authorName ,
                        upsert: true
                        )


                        and you should also define ObjectID otherwise the problem will occur again....



                        const ObjectID = require('mongodb').ObjectID;






                        share|improve this answer



























                          2












                          2








                          2







                          You should use this code because I was also facing the same problem and then I used this code:



                          updateOne(
                          _id: new ObjectID(req.params.id) ,
                          $set: title: req.body.bookName, author: req.body.authorName ,
                          upsert: true
                          )


                          and you should also define ObjectID otherwise the problem will occur again....



                          const ObjectID = require('mongodb').ObjectID;






                          share|improve this answer















                          You should use this code because I was also facing the same problem and then I used this code:



                          updateOne(
                          _id: new ObjectID(req.params.id) ,
                          $set: title: req.body.bookName, author: req.body.authorName ,
                          upsert: true
                          )


                          and you should also define ObjectID otherwise the problem will occur again....



                          const ObjectID = require('mongodb').ObjectID;







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 6 at 8:12









                          Philipp Kief

                          2,84212234




                          2,84212234










                          answered Jul 19 '18 at 9:01









                          nagender pratap chauhannagender pratap chauhan

                          694




                          694



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38883285%2ferror-the-update-operation-document-must-contain-atomic-operators-when-running%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Use pre created SQLite database for Android project in kotlin

                              Darth Vader #20

                              Ondo