Access mongodb database with python

I am following an online course for making web apps with python/mongo/bootstrap.

I install mongodb using default settings

I run mongod in powershell from install directory

C:\Program Files\MongoDB\Server\3.2\bin>mongod
2016-02-27T23:31:14.684-0500 I CONTROL  [initandlisten] MongoDB starting : pid=2456 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-8LMCN7R
2016-02-27T23:31:14.686-0500 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2016-02-27T23:31:14.687-0500 I CONTROL  [initandlisten] db version v3.2.3
2016-02-27T23:31:14.689-0500 I CONTROL  [initandlisten] git version: b326ba837cf6f49d65c2f85e1b70f6f31ece7937
2016-02-27T23:31:14.690-0500 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1p-fips 9 Jul 2015
2016-02-27T23:31:14.692-0500 I CONTROL  [initandlisten] allocator: tcmalloc
2016-02-27T23:31:14.693-0500 I CONTROL  [initandlisten] modules: none
2016-02-27T23:31:14.704-0500 I CONTROL  [initandlisten] build environment:
2016-02-27T23:31:14.706-0500 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2016-02-27T23:31:14.707-0500 I CONTROL  [initandlisten]     distarch: x86_64
2016-02-27T23:31:14.708-0500 I CONTROL  [initandlisten]     target_arch: x86_64
2016-02-27T23:31:14.709-0500 I CONTROL  [initandlisten] options: {}
2016-02-27T23:31:14.712-0500 I -        [initandlisten] Detected data files in C:\data\db\ created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-02-27T23:31:14.715-0500 W -        [initandlisten] Detected unclean shutdown - C:\data\db\mongod.lock is not empty.
2016-02-27T23:31:14.718-0500 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
2016-02-27T23:31:14.720-0500 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=4G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-02-27T23:31:14.954-0500 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-02-27T23:31:14.954-0500 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/data/db/diagnostic.data'
2016-02-27T23:31:14.962-0500 I NETWORK  [initandlisten] waiting for connections on port 27017
2016-02-27T23:31:15.004-0500 I FTDC     [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
2016-02-27T23:32:10.255-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50834 #1 (1 connection now open)

I run mongo in a different powershell from install directory

C:\Program Files\MongoDB\Server\3.2\bin>mongo
MongoDB shell version: 3.2.3
connecting to: test

I confirm that their are some values in my db

> show dbs
fullstack  0.000GB
local      0.000GB
> use fullstack
switched to db fullstack
> show collections
students
> db.students.find({})
{ "_id" : ObjectId("56d1b951d14d4af940b77a14"), "name" : "Jose", "mark" : "99" }
{ "_id" : ObjectId("56d211e8d14d4af940b77a16"), "name" : "Jose", "Mark" : 99 }
{ "_id" : ObjectId("56d26bedc83f1574076c732b"), "name" : "Jose", "mark" : 99 }
{ "_id" : ObjectId("56d26c0fc83f1574076c732c"), "name" : "Kris", "mark" : 69 }
{ "_id" : ObjectId("56d271b1c83f1574076c732d"), "name" : "Kelly", "Grade" : 99 }

I run this code in pyCharm:

import pymongo

uri="mongodb://127.0.0.1:27017"
client = pymongo.MongoClient(uri)
database = client['fullstack']
collection = database['students']
students = collection.find({})
for student in students:
    print(students)

but the interpreter returns nothing. No errors. It just doesn't return anything. The console does not even return a cursor dump. What am I doing wrong?

Answers


I am not sure which of the following steps actually solved the problem. But here is what I did to get the Python console to finally talk to mongod

-Uninstall python -uninstall pycharm -uninstall mongo -remove python environment variables

-reinstalled everything

now it works


I had the same problem after updating mongodb. Upgrading pymongo fixed the problem


Need Your Help

How do I get the row of a custom UITableViewCell using a button in the custom cell, that will be sent to deleteRowsAtIndexPaths

ios uitableview swift

I have made a table view in iOS that displays a list of buddy (friend) requests. For the buddy request cell, I have made it a prototype cell and have given it a custom class that extends from

Linux : How to set up "global" user / passwords / groups file in svn

linux svn configuration passwd authz

I'm trying to set up global user / group access to all my svn repositories on Linux. Since I am very new to svn / linux stuff can someone take a look at what I have set up. I still get a "Invalid a...