search

Home  >  Q&A  >  body text

python3 failed to insert data into mongodb (check Mongovue, there is no data in the database), but no error was reported when the program ran.

code show as below:

#-*-coding:utf8-*-
import pymongo
connection = pymongo.MongoClient()
tdb = connection.jikexueyuan
post_info = tdb.test
jike = {'name':u'极客', 'age':'4', 'skill':'Python'}
gog = {'name':u'天天','age':123, 'skill':'createanything', 'other':u'哈哈'}
godslaver = {'name':u'雨来', 'age':'unknown','other':u'嘻嘻'}
post_info.insert(jike)

print (u'操作数据库完成!')

After the execution is completed, check Mongovue and the results will be displayed as shown below:


The collection is empty. Is this what is the reason?
But if you use another third-party management tool to view it, you can see the created tables and data:


So the problem is with the Mongovue tool? Please answer, thank you

伊谢尔伦伊谢尔伦2726 days ago1574

reply all(1)I'll reply

  • 学习ing

    学习ing2017-07-03 11:43:06

    Maybe you have already opened MongoVUE when inserting. After the data is inserted, the tree structure list on the left is not refreshed, so the tree structure on the left is still displayed in the state before the insertion. You can try right-clicking the left menu to see if the items are refreshed or reloaded.

    In addition, if you click on the tab page before inserting, it is best to close the tab page and reopen it after inserting the data, because the tab may also be in the state before inserting.

    reply
    0
  • Cancelreply