List not showing in pycharm

python
mongo

#1

when i print data from mongo database I am only getting brackets. Pycharm is connected to mongo database.

Pycharm code:
import pymongo

uri=“mongodb://127.0.0.1:27018”
client= pymongo.MongoClient(uri)
database=client[‘norma’]
collection=database[‘students’]

students= [student for student in collection.find({})]
print(students)

output:
/home/tbosss/PycharmProjects/nothing/bin/python /home/tbosss/PycharmProjects/nothing/src/app.py
[]

Process finished with exit code 0

Here the mongo db and collections:

tbosss@tbosss:~$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
Server has startup warnings:
2018-06-30T17:30:54.661+0400 I STORAGE [initandlisten]
2018-06-30T17:30:54.661+0400 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-06-30T17:30:54.661+0400 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-06-30T17:30:58.754+0400 I CONTROL [initandlisten]
2018-06-30T17:30:58.754+0400 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-06-30T17:30:58.754+0400 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-06-30T17:30:58.754+0400 I CONTROL [initandlisten]

show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
norma 0.000GB
use norma
switched to db norma
show collections
nextra
students
db.students.find()
{ “_id” : ObjectId(“5b3790c5582843c46e144f60”), “name” : “jack”, “class” : “m”, “id” : “789564” }

this is mongod connection and its connected:

2018-06-30T21:04:15.997+0400 I NETWORK [listener] connection accepted from 127.0.0.1:39960 #3 (2 connections now open)
2018-06-30T21:04:15.997+0400 I NETWORK [conn3] received client metadata from 127.0.0.1:39960 conn: { driver: { name: “PyMongo”, version: “3.7.0” }, os: { type: “Linux”, name: “Linux”, architecture: “x86_64”, version: “4.15.0-23-generic” }, platform: “CPython 3.6.5.final.0” }
2018-06-30T21:04:16.501+0400 I NETWORK [conn3] end connection 127.0.0.1:39960 (1 connection now open)
2018-06-30T21:04:16.501+0400 I NETWORK [conn2] end connection 127.0.0.1:39958 (0 connections now open)


#2

different uri’s


#3

Different…Where…? If you are talking about port 27017 then I changed the port myself to 27018


#4

It was a difference and it could have explained the different outcome so there wasn’t much point in looking any further!

It’s also the only difference you showed, copying the rest produces the same result for both:

$ mongo
connecting to: mongodb://127.0.0.1:27017
> use norma
switched to db norma
> db.students.find()
{ "_id" : ObjectId("5b38b2c6331f1a07777c938f"), "name" : "jack", "class" : "m", "id" : "789564" }
$ python
>>> import pymongo
>>> db=pymongo.MongoClient('mongodb://127.0.0.1:27017')['norma']
>>> list(db['students'].find())
[{'_id': ObjectId('5b38b2c6331f1a07777c938f'), 'name': 'jack', 'class': 'm', 'id': '789564'}]            

I think a reasonable conclusion is therefore that you either connected to a different mongod instance or modified the database between testing with your two clients


#5

thanx man i was connecting to different instance


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.