I am trying to iterate over a query, returning various dicts to which I will eventually code to insert into an array.
My problem at the moment is that my code works in the shell, but it does not work in the script.
Here is my code:
cursor = db.model.find({'time': {'$gte': start, '$lt': end}}).sort('time')
for result in cursor:
result['_id']
When used in the shell, it returns the ids. When used in the script, it simply skips it like it never happened. In both scenarios, if I add print (result) I get the entire result.
I would appreciate help and an explanation. Thanks.
Use
printstatement explicitly:Shell automatically shows each calculated value (i.e.
result['_id']) while script does not so. In order to write some data to stdout you should useprintexplicitly.