Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用pymongo处理大量集合_Python_Mongodb_Cursor_Pymongo - Fatal编程技术网

Python 如何使用pymongo处理大量集合

Python 如何使用pymongo处理大量集合,python,mongodb,cursor,pymongo,Python,Mongodb,Cursor,Pymongo,我在网上到处寻找我的问题,但有点卡住了,我试图使用pymongo使用游标查看MongoDB上的大量集合,但是它发现在python中没有像JS这样的hasNext()实现 这是我的密码: cursor = news.find() while(cursor.hasNext()): doc = cursor.next() 明白了 pymongo没有hasNext(),相反,如果没有更多的对象,方法next()将返回None,所以这就是诀窍 谢谢你 您可以通过查看集合中的语句 fo

我在网上到处寻找我的问题,但有点卡住了,我试图使用pymongo使用游标查看MongoDB上的大量集合,但是它发现在python中没有像JS这样的hasNext()实现

这是我的密码:

cursor = news.find() 
while(cursor.hasNext()):    
     doc = cursor.next()
明白了

pymongo没有hasNext(),相反,如果没有更多的对象,方法next()将返回None,所以这就是诀窍


谢谢你

您可以通过查看集合中的语句

for record in cursor:
  print record
for关键字实际上为您调用了\u iter()next()

pymongo中的Cursor对象附带以下两种方法。