python 3.x - What happens to a pymongo cursor when all its elements have been iterated? -


i wanted use pymongo array of entries database. seems return "cursor" instead. don't know is.

    all_nodes = pymongo.mongoclient("mongodb://localhost")["provemath"]["nodes"].find(none)      print('all nodes')     node in all_nodes:         print(node)      print('still nodes')     node in all_nodes:         print(node) 

there output is:

all nodes {'_notes': [], '_examples': [], '_type': 'definition', '_plural': none, '_counterexamples': [], '_intuitions': [], '_id': 'unique', '_importance': 4, '_name': 'unique', '_dependencies': [], '_description': 'an occurence of property __unique__ if property occurs $1$ time.'} {'_notes': ['vertices drawn dot.  called *nodes*.'], '_examples': [], '_type': 'definition', '_plural': '__vertices__', '_counterexamples': [], '_intuitions': [], '_id': 'vertex', '_importance': 4, '_name': 'vertex', '_dependencies': ['unique'], '_description': 'a __vertex__ fundamental unit used create graphs.'} {'_notes': ['it possible $a=b$.'], '_examples': [], '_type': 'definition', '_plural': none, '_counterexamples': [], '_intuitions': ['edges drawn line or curve connecting 2 vertices.  in case $a=b$, edge drawn small loop connects $a$ itself.'], '_id': 'edge', '_importance': 4, '_name': 'edge', '_dependencies': ['unique', 'vertex'], '_description': 'an __edge__ set ${a,b}$ $a$ , $b$ vertices.'} {'_notes': [], '_examples': [], '_type': 'definition', '_plural': none, '_counterexamples': [], '_intuitions': [], '_id': 'loop', '_importance': 4, '_name': 'loop', '_dependencies': [], '_description': 'a __loop__ edge $e = {a,a} = {a}$.'} still nodes 

is cursor 1 use? (or else going on?) if wanted regular array behavior, how that?

yes. cursor 1 use. described in mongodb manual

by default, server automatically close cursor after 10 minutes of inactivity or if client has exhausted cursor.

to make output python list use

node_list = all_nodes[:] 

or

node_list = [node node in all_nodes]  

see this question


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -