Sreeraj
Sreeraj

Reputation: 18

Pymongo importing succeeded but not showing in the collection

I tried importing json file which succeeded

mongoimport --db dbwhy --collection dbcol --jsonArray consumer_complaint.json
2016-01-15T19:00:42.277-0600    connected to: localhost
2016-01-15T19:00:42.320-0600    imported 34 documents

but when I tried viewing it, it was not there

from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dbwhy']
coll = db['dbcol']
curs = db.coll.find()
for i in curs:
    print(i)

It does not show anything

Upvotes: 0

Views: 38

Answers (1)

alecxe
alecxe

Reputation: 473893

The problem is here:

db.coll.find()

This would find all documents inside the coll collection, but your collection is named dbcol.

Instead, use the coll variable that you've already defined:

from pymongo import MongoClient

client = MongoClient('localhost',27017)

db = client['dbwhy']
coll = db['dbcol']

curs = coll.find()  # FIX is here
for i in curs:
    print(i)

Upvotes: 1

Related Questions