How to create a new database and collection using pymongo?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-2
down vote

favorite
1












I wanna create database and collection using python script so that I used pymongo driver. But i am unable to create database.
steps I followed.



from pymongo import MongoClient
con = MongoClient('localhost', 27017)
db = con.testdb


After this commands when i checked in mongoshell the db "testdb" is not created.



Can i use paramiko to interact with mongo shell ?



python version : 2.7



Answer would be appreciated.







share|improve this question




















  • MongoDB creates new databases implicitly upon their first use, so you need to insert at least one document into a collection in testdb in order to see the database created.
    – Stennie
    Apr 1 at 13:19














up vote
-2
down vote

favorite
1












I wanna create database and collection using python script so that I used pymongo driver. But i am unable to create database.
steps I followed.



from pymongo import MongoClient
con = MongoClient('localhost', 27017)
db = con.testdb


After this commands when i checked in mongoshell the db "testdb" is not created.



Can i use paramiko to interact with mongo shell ?



python version : 2.7



Answer would be appreciated.







share|improve this question




















  • MongoDB creates new databases implicitly upon their first use, so you need to insert at least one document into a collection in testdb in order to see the database created.
    – Stennie
    Apr 1 at 13:19












up vote
-2
down vote

favorite
1









up vote
-2
down vote

favorite
1






1





I wanna create database and collection using python script so that I used pymongo driver. But i am unable to create database.
steps I followed.



from pymongo import MongoClient
con = MongoClient('localhost', 27017)
db = con.testdb


After this commands when i checked in mongoshell the db "testdb" is not created.



Can i use paramiko to interact with mongo shell ?



python version : 2.7



Answer would be appreciated.







share|improve this question












I wanna create database and collection using python script so that I used pymongo driver. But i am unable to create database.
steps I followed.



from pymongo import MongoClient
con = MongoClient('localhost', 27017)
db = con.testdb


After this commands when i checked in mongoshell the db "testdb" is not created.



Can i use paramiko to interact with mongo shell ?



python version : 2.7



Answer would be appreciated.









share|improve this question











share|improve this question




share|improve this question










asked Apr 1 at 6:25









Abdulvakaf K

294




294











  • MongoDB creates new databases implicitly upon their first use, so you need to insert at least one document into a collection in testdb in order to see the database created.
    – Stennie
    Apr 1 at 13:19
















  • MongoDB creates new databases implicitly upon their first use, so you need to insert at least one document into a collection in testdb in order to see the database created.
    – Stennie
    Apr 1 at 13:19















MongoDB creates new databases implicitly upon their first use, so you need to insert at least one document into a collection in testdb in order to see the database created.
– Stennie
Apr 1 at 13:19




MongoDB creates new databases implicitly upon their first use, so you need to insert at least one document into a collection in testdb in order to see the database created.
– Stennie
Apr 1 at 13:19










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










From http://api.mongodb.com/python/current/tutorial.html



It states



An important note about collections (and databases) in MongoDB is that 
they are created lazily - none of the above commands have actually
performed any operations on the MongoDB server. **Collections and
databases are created when the first document is inserted into them.**





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f434791%2fhow-to-create-a-new-database-and-collection-using-pymongo%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    From http://api.mongodb.com/python/current/tutorial.html



    It states



    An important note about collections (and databases) in MongoDB is that 
    they are created lazily - none of the above commands have actually
    performed any operations on the MongoDB server. **Collections and
    databases are created when the first document is inserted into them.**





    share|improve this answer
























      up vote
      0
      down vote



      accepted










      From http://api.mongodb.com/python/current/tutorial.html



      It states



      An important note about collections (and databases) in MongoDB is that 
      they are created lazily - none of the above commands have actually
      performed any operations on the MongoDB server. **Collections and
      databases are created when the first document is inserted into them.**





      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        From http://api.mongodb.com/python/current/tutorial.html



        It states



        An important note about collections (and databases) in MongoDB is that 
        they are created lazily - none of the above commands have actually
        performed any operations on the MongoDB server. **Collections and
        databases are created when the first document is inserted into them.**





        share|improve this answer












        From http://api.mongodb.com/python/current/tutorial.html



        It states



        An important note about collections (and databases) in MongoDB is that 
        they are created lazily - none of the above commands have actually
        performed any operations on the MongoDB server. **Collections and
        databases are created when the first document is inserted into them.**






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 2 at 8:38









        Abdulvakaf K

        294




        294






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f434791%2fhow-to-create-a-new-database-and-collection-using-pymongo%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay