Insert_one no such method exists @ pymongo 3.7.2











up vote
0
down vote

favorite












I´m pretty new learning Python and all the containing stuff.



I tried to make my first little steps, installing a MongoDB (working) and connecting to it.



from pymongo import MongoClient
from pprint import pprint
from random import randint



client = MongoClient('localhost', 27017)
db = client.test
collection = db.users

user = {"id": 1, "username": "Test"}

user_id = collection.insert_one(user).inserted_id
print(user_id)


This is the complete code.



pymongo Version: 3.7.2 checked with:



pip freeze | grep pymongo
Output: pymongo==3.7.2


Python Version: 3.7.1



If I try to execute my tiny script, the following error occurs:



'Collection' object is not callable. 
If you meant to call the 'insert_one' method on a 'Collection'
object it is
failing because no such method exists.


Where is my Fault?



A little research showed that in pymongo v2 the ".insert_one" is ".insert", but the 3.7.2 version is installed so I should (and must) use the ".insert.one", not the ".insert"










share|improve this question


























    up vote
    0
    down vote

    favorite












    I´m pretty new learning Python and all the containing stuff.



    I tried to make my first little steps, installing a MongoDB (working) and connecting to it.



    from pymongo import MongoClient
    from pprint import pprint
    from random import randint



    client = MongoClient('localhost', 27017)
    db = client.test
    collection = db.users

    user = {"id": 1, "username": "Test"}

    user_id = collection.insert_one(user).inserted_id
    print(user_id)


    This is the complete code.



    pymongo Version: 3.7.2 checked with:



    pip freeze | grep pymongo
    Output: pymongo==3.7.2


    Python Version: 3.7.1



    If I try to execute my tiny script, the following error occurs:



    'Collection' object is not callable. 
    If you meant to call the 'insert_one' method on a 'Collection'
    object it is
    failing because no such method exists.


    Where is my Fault?



    A little research showed that in pymongo v2 the ".insert_one" is ".insert", but the 3.7.2 version is installed so I should (and must) use the ".insert.one", not the ".insert"










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I´m pretty new learning Python and all the containing stuff.



      I tried to make my first little steps, installing a MongoDB (working) and connecting to it.



      from pymongo import MongoClient
      from pprint import pprint
      from random import randint



      client = MongoClient('localhost', 27017)
      db = client.test
      collection = db.users

      user = {"id": 1, "username": "Test"}

      user_id = collection.insert_one(user).inserted_id
      print(user_id)


      This is the complete code.



      pymongo Version: 3.7.2 checked with:



      pip freeze | grep pymongo
      Output: pymongo==3.7.2


      Python Version: 3.7.1



      If I try to execute my tiny script, the following error occurs:



      'Collection' object is not callable. 
      If you meant to call the 'insert_one' method on a 'Collection'
      object it is
      failing because no such method exists.


      Where is my Fault?



      A little research showed that in pymongo v2 the ".insert_one" is ".insert", but the 3.7.2 version is installed so I should (and must) use the ".insert.one", not the ".insert"










      share|improve this question













      I´m pretty new learning Python and all the containing stuff.



      I tried to make my first little steps, installing a MongoDB (working) and connecting to it.



      from pymongo import MongoClient
      from pprint import pprint
      from random import randint



      client = MongoClient('localhost', 27017)
      db = client.test
      collection = db.users

      user = {"id": 1, "username": "Test"}

      user_id = collection.insert_one(user).inserted_id
      print(user_id)


      This is the complete code.



      pymongo Version: 3.7.2 checked with:



      pip freeze | grep pymongo
      Output: pymongo==3.7.2


      Python Version: 3.7.1



      If I try to execute my tiny script, the following error occurs:



      'Collection' object is not callable. 
      If you meant to call the 'insert_one' method on a 'Collection'
      object it is
      failing because no such method exists.


      Where is my Fault?



      A little research showed that in pymongo v2 the ".insert_one" is ".insert", but the 3.7.2 version is installed so I should (and must) use the ".insert.one", not the ".insert"







      python pymongo pymongo-3.x






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 17:51









      Exitare

      126113




      126113
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          insert_one according with pymongo documentation exists, for server version >= 3.2...



          the use is:



          user = {'x': 1}
          result = db.test.insert_one(user)
          result.inserted_id


          more complete explanation about insert_one:



          >>> db.test.count_documents({'x': 1})
          0
          >>> result = db.test.insert_one({'x': 1})
          >>> result.inserted_id
          ObjectId('54f112defba522406c9cc208')
          >>> db.test.find_one({'x': 1})
          {u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}


          the following below, I executed and works fine:



          # importing client mongo to make the connection
          from pymongo import MongoClient

          print("--- Exemplo pymongo Connection ---")

          # Connection to MongoDB
          client = MongoClient('localhost', 27017)

          # Selection the Database
          db = client.python

          # Select the collection
          collection = db.users

          # Set up a document
          user = {"id": 1, "username": "Test"}

          # insert one document into selected document
          result = collection.insert_one(user)

          # Selection just one document from collection
          #result = collection.find_one()

          # removing the document inserted
          collection.delete_one(user)

          # print the inserted_id
          print("inserted_id: ", result.inserted_id)


          Pymongo Documentation






          share|improve this answer



















          • 1




            Thanks for the Hint. I solved it.
            – Exitare
            Nov 8 at 18:12











          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',
          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%2f53213476%2finsert-one-no-such-method-exists-pymongo-3-7-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          insert_one according with pymongo documentation exists, for server version >= 3.2...



          the use is:



          user = {'x': 1}
          result = db.test.insert_one(user)
          result.inserted_id


          more complete explanation about insert_one:



          >>> db.test.count_documents({'x': 1})
          0
          >>> result = db.test.insert_one({'x': 1})
          >>> result.inserted_id
          ObjectId('54f112defba522406c9cc208')
          >>> db.test.find_one({'x': 1})
          {u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}


          the following below, I executed and works fine:



          # importing client mongo to make the connection
          from pymongo import MongoClient

          print("--- Exemplo pymongo Connection ---")

          # Connection to MongoDB
          client = MongoClient('localhost', 27017)

          # Selection the Database
          db = client.python

          # Select the collection
          collection = db.users

          # Set up a document
          user = {"id": 1, "username": "Test"}

          # insert one document into selected document
          result = collection.insert_one(user)

          # Selection just one document from collection
          #result = collection.find_one()

          # removing the document inserted
          collection.delete_one(user)

          # print the inserted_id
          print("inserted_id: ", result.inserted_id)


          Pymongo Documentation






          share|improve this answer



















          • 1




            Thanks for the Hint. I solved it.
            – Exitare
            Nov 8 at 18:12















          up vote
          1
          down vote













          insert_one according with pymongo documentation exists, for server version >= 3.2...



          the use is:



          user = {'x': 1}
          result = db.test.insert_one(user)
          result.inserted_id


          more complete explanation about insert_one:



          >>> db.test.count_documents({'x': 1})
          0
          >>> result = db.test.insert_one({'x': 1})
          >>> result.inserted_id
          ObjectId('54f112defba522406c9cc208')
          >>> db.test.find_one({'x': 1})
          {u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}


          the following below, I executed and works fine:



          # importing client mongo to make the connection
          from pymongo import MongoClient

          print("--- Exemplo pymongo Connection ---")

          # Connection to MongoDB
          client = MongoClient('localhost', 27017)

          # Selection the Database
          db = client.python

          # Select the collection
          collection = db.users

          # Set up a document
          user = {"id": 1, "username": "Test"}

          # insert one document into selected document
          result = collection.insert_one(user)

          # Selection just one document from collection
          #result = collection.find_one()

          # removing the document inserted
          collection.delete_one(user)

          # print the inserted_id
          print("inserted_id: ", result.inserted_id)


          Pymongo Documentation






          share|improve this answer



















          • 1




            Thanks for the Hint. I solved it.
            – Exitare
            Nov 8 at 18:12













          up vote
          1
          down vote










          up vote
          1
          down vote









          insert_one according with pymongo documentation exists, for server version >= 3.2...



          the use is:



          user = {'x': 1}
          result = db.test.insert_one(user)
          result.inserted_id


          more complete explanation about insert_one:



          >>> db.test.count_documents({'x': 1})
          0
          >>> result = db.test.insert_one({'x': 1})
          >>> result.inserted_id
          ObjectId('54f112defba522406c9cc208')
          >>> db.test.find_one({'x': 1})
          {u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}


          the following below, I executed and works fine:



          # importing client mongo to make the connection
          from pymongo import MongoClient

          print("--- Exemplo pymongo Connection ---")

          # Connection to MongoDB
          client = MongoClient('localhost', 27017)

          # Selection the Database
          db = client.python

          # Select the collection
          collection = db.users

          # Set up a document
          user = {"id": 1, "username": "Test"}

          # insert one document into selected document
          result = collection.insert_one(user)

          # Selection just one document from collection
          #result = collection.find_one()

          # removing the document inserted
          collection.delete_one(user)

          # print the inserted_id
          print("inserted_id: ", result.inserted_id)


          Pymongo Documentation






          share|improve this answer














          insert_one according with pymongo documentation exists, for server version >= 3.2...



          the use is:



          user = {'x': 1}
          result = db.test.insert_one(user)
          result.inserted_id


          more complete explanation about insert_one:



          >>> db.test.count_documents({'x': 1})
          0
          >>> result = db.test.insert_one({'x': 1})
          >>> result.inserted_id
          ObjectId('54f112defba522406c9cc208')
          >>> db.test.find_one({'x': 1})
          {u'x': 1, u'_id': ObjectId('54f112defba522406c9cc208')}


          the following below, I executed and works fine:



          # importing client mongo to make the connection
          from pymongo import MongoClient

          print("--- Exemplo pymongo Connection ---")

          # Connection to MongoDB
          client = MongoClient('localhost', 27017)

          # Selection the Database
          db = client.python

          # Select the collection
          collection = db.users

          # Set up a document
          user = {"id": 1, "username": "Test"}

          # insert one document into selected document
          result = collection.insert_one(user)

          # Selection just one document from collection
          #result = collection.find_one()

          # removing the document inserted
          collection.delete_one(user)

          # print the inserted_id
          print("inserted_id: ", result.inserted_id)


          Pymongo Documentation







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 8 at 18:33

























          answered Nov 8 at 18:05









          Sham Fiorin

          208




          208








          • 1




            Thanks for the Hint. I solved it.
            – Exitare
            Nov 8 at 18:12














          • 1




            Thanks for the Hint. I solved it.
            – Exitare
            Nov 8 at 18:12








          1




          1




          Thanks for the Hint. I solved it.
          – Exitare
          Nov 8 at 18:12




          Thanks for the Hint. I solved it.
          – Exitare
          Nov 8 at 18:12


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53213476%2finsert-one-no-such-method-exists-pymongo-3-7-2%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

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)