How to efficiently do a limit query on MongoDB GridFS -


i cannot seem find efficient way query against mongodb gridfs contains limit of n files.

here have tried.

dbcursor filelist = products.getfilelist().limit(10); while(filelist.hasnext()){     dbobject filedef = filelist.next();     file = products.findone((string)filedef.get("filename"));     inputstream stream = file.getinputstream();     ... } 

the problem there 21 query operations occur.

first getfilelist() calls dbcollection.find().

then each result findone() occurs ends calling dbcollection.find({"filename":filename}) 10 times.

after that, when call read on input stream, calls findone("files_id":id) on chunks collection 10 files.


i noticed in gridfs.find() queries files collection, converts each dbobject gridfsdbfile, , sets (fs) variable this(gridfs). (all via injectgridfsinstance(object))

if getfilelist() operation did well, returns standard cursor. can cast dbobject gridfsdbfile when try call read on inputstream complains there no gridfs instance defined , therefore not have information needs go , chunks.

i love able set fs variable private.


bottom line:

is there way query on gridfs includes .limit(n) not have double number of query operations.


Comments

Popular posts from this blog

angularjs - Redirect to a new template in angular js -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -

Desktop Launcher for Python Script Starts Program in Wrong Path (Linux) -