Unable to access large Mongodb collection

We have 2 collections in Mongodb.
Coll1 : 9gb, 7k documents
Coll2: 12gb, 20k documents

I am able to access Coll1 from python(pymongo) and fetch the document using find_one().
But when I try to fetch from Coll2, I get None as output for the same find_one() function.

Also, I am able to access Coll2 from Mongodb Compass.

Posting your schema, an example document, and a code sample would help.
My first wild and unsubstantiated guess is that you’re addressing a non-existent db or collection.

1 Like

Hi Jack

Python code:

#! /usr/bin/python3.7
import json
import pymongo
myclient = pymongo. Mongoclient(host='mongodb://hostname:27017', username='', password='', authSource='admin') 
collectionname = dbname. Collection2
doc1=collectionname.find_one() 
print(doc1) 

Also, the document in both Collection1 and Collection 2 have the same structure.

Both the collection contains document of same structure. Each document has an Array field with 1000 subdocuments.

Statement: Array
>0: object
     id:1
     >address: object
        street: string
        zip: string
      >address1: object
         street:string
         zip:string
>1:object
>2:object
...... 
>999:object

How is dbname defined?

In one post it is Coll1 and Coll2 while in the other it is Collection2. Which one is the correct one? Often, issues like the one you described, are caused by misspelling database or collection names. It is really hard to find if it is case if you provide made-up names or altered sample code that do not contains the misspelling errors.

Please provide a screenshot of compass that shows the 2 collections within their respective database.

I do not know python enough but the space between dbname. and Collection2 might be significatif.

2 Likes

Hi Jack… Do you need any additional info?

@Ananth_Nagiah everthing @steevej said in his post is true: the code you posted does not make sense to either of us. Furthermore, I think Steeve is probably more expert than I am, so you should work with him and provide the information he requests.

Thanks for the compliment but I would not consider that I am. See

Any information posted will be useful to all whom have time to help.

Have a good day Jack!

2 Likes

We’ll work it out together if we get some good code and data from the OP!

1 Like