MongoDB: Cursor.count() is > 0 but serializing return an empty array

467
August 12, 2017, at 09:50 AM

Im writing a database API using pymongo, and I've run into a problem:

Consider the following code:

mongo_client = MongoClient('mongodb://mongodb:27017/')
db = mongo_client.test_database
orders = db['Orders']
buy_orders = orders.find({'asset_pair': 'USD-EUR'})
print(buy_orders.count()
for doc in buy_orders:
   print(doc)

Problem: The for loop is not executed, even though count() prints 8 (there should be 8 docs). Question: Am I missing something? Why is the for-loop not executed 8 times, if the cursors count is 8?

Also:

from bson import json_util
json.dumps(buy_orders, default=json_util.default)

returns an empty array. Any help is appreciated!

Edit my my application is multi threaded. A separate thread writes to the collection I'm searching.

READ ALSO
Is it possible to automate the combination of excel cells

Is it possible to automate the combination of excel cells

I have data in an excel file organized like this:

184
Pass data frame through Tkinter classes

Pass data frame through Tkinter classes

I am using Python 27 and Tkinter

317
How to install tensorflow with virtualenvwrapper on macOS-Sierra

How to install tensorflow with virtualenvwrapper on macOS-Sierra

I need to install TensorFlow on macOS-Sierra and I want to use virtualenvwrapper for thatTo install TensorFlow one could follow the virtualenv installation walk-through provided by TensorFlow website

329
Change every occurrence of a date to another format with regex

Change every occurrence of a date to another format with regex

I'm doing my first steps with regex and I'm still a little bit confused about the syntaxI want to detect the end of sentences trough a period

290