我正在使用gridFS,它在我写完一个文件后出现,如果我立即执行读操作试图找到它,mongoDB会抛出一个运行时异常,但它似乎是间歇性的。
导致它的java代码是:
List<GridFSDBFile> files = PlayJongo.gridfs().find(filename);GridFS类的驱动中的相关代码如下:
/**
* finds a list of files matching the given query
* @param query
* @param sort
* @return
* @throws MongoException
*/
public List<GridFSDBFile> find( DBObject query , DBObject sort){
List<GridFSDBFile> files = new ArrayList<GridFSDBFile>();
DBCursor c = null;
try {
c = _filesCollection.find( query );
if (sort != null) {
c.sort(sort);
}
while ( c.hasNext() ){
files.add( _fix( c.next() ) );
}
} finally {
if (c != null){
c.close();
}
}
return files;
}
protected GridFSDBFile _fix( Object o ){
if ( o == null )
return null;
if ( ! ( o instanceof GridFSDBFile ) )
throw new RuntimeException( "somehow didn't get a GridFSDBFile" );
GridFSDBFile f = (GridFSDBFile)o;
f._fs = this;
return f;
}我使用的是带有Jongo包装器的play!2.1,但它们不会影响它,因为我是使用mongodb的java驱动程序直接访问gridFS的。
奇怪的是,如果我调试的数据实际上是在对象中,但它不是驱动程序期望的对象:

有没有人遇到过这种情况?
发布于 2013-07-10 05:15:20
找到答案了。如果使用jongo api访问fs.files集合,即使直接使用mongoDB驱动程序,也会中断对gridFS文件系统的进一步访问。
修补程序已发布,但尚未集成到发行版中
补丁:https://github.com/bguerout/jongo/commit/0d27ba3ebfd065e7bf4ad323ee21059b762b512e
发布于 2014-08-10 07:29:13
有关此错误修复的更多详细信息:
Class fs.files.getObjectClass();
fs.files.setObjectClass(save)
https://stackoverflow.com/questions/17552264
复制相似问题