针对pymongo.errors.CursorNotFound:游标ID“...”在服务器上无效和游标%notfound这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展android–Cur
针对pymongo.errors.CursorNotFound:游标ID“ ...”在服务器上无效和游标%notfound这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展android – Cursor.moveToNext()返回false,而Cursor.getCount()表示超过1行、android – onrsor Listener for CursorAdapter、android-使用cursor.respond(Bundle)和cursor.getextras()、apache服务器上wsgi的ModuleNotFoundError等相关知识,希望可以帮助到你。
本文目录一览:- pymongo.errors.CursorNotFound:游标ID“ ...”在服务器上无效(游标%notfound)
- android – Cursor.moveToNext()返回false,而Cursor.getCount()表示超过1行
- android – onrsor Listener for CursorAdapter
- android-使用cursor.respond(Bundle)和cursor.getextras()
- apache服务器上wsgi的ModuleNotFoundError
pymongo.errors.CursorNotFound:游标ID“ ...”在服务器上无效(游标%notfound)
我正在尝试使用以下代码获取mongo数据库中存在的一些ID:
client = MongoClient(''xx.xx.xx.xx'', xxx)db = client.test_databasedb = client[''...'']collection = db.test_collectioncollection = db["..."]for cursor in collection.find({ "$and" : [{ "followers" : { "$gt" : 2000 } }, { "followers" : { "$lt" : 3000 } }, { "list_followers" : { "$exists" : False } }] }): print cursor[''screenname''] print cursor[''_id''][''uid''] id = cursor[''_id''][''uid'']
但是,过了一会儿,我收到此错误:
pymongo.errors.CursorNotFound:游标ID’…’在服务器上无效。
我发现这篇文章提到了这个问题。不过,我不清楚该采取哪种解决方案。可以使用find().batch_size(30)
吗?上面的命令到底是做什么的?我可以使用所有数据库IDbatch_size
吗?
答案1
小编典典由于光标在服务器上超时(不活动10分钟后),因此出现此错误。
从pymongo文档中:
如果MongoDB中的游标已打开很长时间而未对其执行任何操作,则它们可能会在服务器上超时。尝试迭代游标时,这可能导致引发CursorNotFound异常。
当您调用该collection.find
方法时,它查询一个集合,并将光标返回到文档。要获取文档,请迭代光标。当您遍历游标时,驱动程序实际上是在向MongoDB服务器发出请求以从服务器获取更多数据。每个请求中返回的数据量由batch_size()
方法设置。
从文档中:
限制一批中返回的文档数。每个批次都需要往返服务器。可以对其进行调整以优化性能并限制数据传输。
将batch_size设置为较小的值将帮助您解决超时错误错误,但是它将增加访问MongoDB服务器获取所有文档的次数。
默认批处理大小:
对于大多数查询,第一批返回101个文档或刚好超过1兆字节的文档。批处理大小不会超过BSON文档的最大大小(16 MB)。
没有通用的“正确”批次大小。您应该使用不同的值进行测试,并查看适合您的用例的合适值,即在10分钟的窗口中可以处理多少个文档。
不得已而为您no_cursor_timeout=True
。但是,您需要确保在处理完数据后关闭游标。
如何避免以下情况try/except
:
cursor = collection.find( {"x": 1}, no_cursor_timeout=True)for doc in cursor: # do something with doccursor.close()
android – Cursor.moveToNext()返回false,而Cursor.getCount()表示超过1行
我将结果保存在我的Cursor中,并且我正在迭代它以获得所有结果..
allotugh我正在检查并看到光标有超过1行,它只给我第一行,因为movetoNext()总是返回false.
这是我的迭代代码:
Cursor cursor = getEventsDetails(db,selection,null); Log.e("cursor before","count" + cursor.getCount()); boolean movetoNext = cursor.movetoFirst(); if (movetoNext) { do { //Create a new PicoEvent instance with the event''s details PicoEvent event = PicoEventCreator.createPicoEvent(cursor); Log.e(event.getName(),event.getStartTime().toLocaleString()); Log.e("cursor in","count" + cursor.getCount()); movetoNext = cursor.movetoNext(); Log.e("movetoNext","move: " + movetoNext); if (!isEventExists(eventsList,event)) eventsList.add(event); } while (movetoNext); }
这是Logcat调试:
12-01 17:33:07.774: E/cursor before(5950): count4 12-01 17:33:08.094: E/Pico Demo Event(5950): 1 בדצמ 2013 11:00:00 12-01 17:33:08.124: E/cursor in(5950): count4 12-01 17:33:08.124: E/movetoNext(5950): move: false
正如你所看到的行数是4,但这一举动是错误的……
解决方法
PicoEvent event = PicoEventCreator.createPicoEvent(cursor);
我敢打赌,该方法是在光标返回之前将光标推进到最后.
android – onrsor Listener for CursorAdapter
我创建了一个自定义的CursorAdapter并想要选择一个列表项,以便在onoptionsItemSelected中启动一个动作.
创建列表视图:
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate called");
super.onCreate(savedInstanceState);
Log.d(TAG, "create DatabaSEOpenHelper");
DatabaSEOpenHandler helper = new DatabaSEOpenHandler(this);
Log.d(TAG, "get writeable database access");
database = helper.getWritableDatabase();
Log.d(TAG, "create Cursor for database access");
Cursor data = database.query(DatabaseConstants.TABLE_NOTES, fields,
null, null, null, null, null);
Log.d(TAG, "set NoteCursorAdapeter");
setlistadapter(new NoteCursorAdapter(this, data));
}
onoptionItemSelected:
public boolean onoptionsItemSelected(MenuItem item) {
Log.d(TAG, "onoptionItemSelected called");
switch (item.getItemId()) {
case R.id.conference_note_menu_new:
Toast.makeText(this, "Es sind keine Einstellungen verfügbar",
Toast.LENGTH_LONG).show();
return true;
case R.id.conference_note_menu_edit:
Toast.makeText(this, "Es sind keine Einstellungen verfügbar",
Toast.LENGTH_LONG).show();
return true;
case R.id.conference_note_menu_delete:
Toast.makeText(this, "Es sind keine Einstellungen verfügbar",
Toast.LENGTH_LONG).show();
return true;
default:
return super.onoptionsItemSelected(item);
}
}
在互联网上找不到任何有用的信息.
解决方法:
onoptionItemSelected用于菜单.你需要为ListView设置onItemClickListener,如下所示:
getListView().setonItemClickListener(this);
和实施:
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// Todo Auto-generated method stub
}
android-使用cursor.respond(Bundle)和cursor.getextras()
我在sqlite数据库的不同表中有2个游标.我试图将来自两个游标的数据放到一个ListView中,但是要为来自每个游标的数据设置不同的格式.
我想到的是使用MergeCursor组合两个光标,但是我的SimpleCursorAdapter的ViewBinder会将它们视为单个光标,并且无法区分格式(除非我更改了我不想做的表) .
最后,我找到了两种称为Cursor.repond(Bundle)& Cursor.getExtras(),但是开发者控制台上的文档非常简短,因此对这些方法进行谷歌搜索无法明确其用法.
我测试了在数据库类中对查询使用resond()的想法:
extr.putString("table", the_tab);
Cursor c_in = db.rawQuery(qry, null);
c_in.respond(extr);
return c_in;
并在ViewBinder中使用getExtras()来了解查询表并相应地格式化ListView项:
Bundle extr=cur.getExtras();
String tab= extr.getString("table");
但是我总是遇到一个例外,那就是制表符为null.
经过这么长的描述之后,我的问题是:我是否正确使用了response和getExtras方法?如果不是,是否有更好的方法解决我的问题?
解决方法:
尝试在两个SELECT中将表名作为字段构建.
SELECT "A", * from tableA; SELECT "B", * from tableB;
然后计算合并的游标.交替,
SELECT "A", * from tableA UNION ALL SELECT "B", * from tableB;
现在,如果光标的每一行来自表A,则在第一列中将有一个“ A”,如果来自表B,则将具有“ B”.因此,很容易在ViewBinder中查看此列以制定格式决策.
apache服务器上wsgi的ModuleNotFoundError
这可能是因为模块不在路径中(您可能不正确地更改了路径)或类似的东西。可能是模块放置不正确或以某种方式删除了该模块。我是菜鸟,但我会尽力提供帮助。
,原来,.local和站点包都没有执行权限。 我以为读取权限允许遍历目录,但显然是执行权限。
我只是在两个目录上运行了chmod a+x directoryName
,它起作用了。
我还必须取消对WSGIPythonPath行的注释。
关于pymongo.errors.CursorNotFound:游标ID“ ...”在服务器上无效和游标%notfound的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于android – Cursor.moveToNext()返回false,而Cursor.getCount()表示超过1行、android – onrsor Listener for CursorAdapter、android-使用cursor.respond(Bundle)和cursor.getextras()、apache服务器上wsgi的ModuleNotFoundError的相关知识,请在本站寻找。
本文标签: