Skip to content
dizzzz edited this page Sep 24, 2014 · 6 revisions

###Reuse of the client A GridFS operation could be performed by opening a connection, execute a function with the $mongodbClientId and finally close the connection. The MongoDB java driver, which is used under the hood, is efficient with reusing and caching database connections. An example:

let $mongodbClientId := mongodb:connect($mongoUrl)
grifd:function($mongodbClientId, ...., ....)
mongodb:close($mongodbClientId)

The drawback of this approach is that the $mongoUrl (potententially containing username/password and configuration information) needs to be copied or re-used in each xquery script.

Fortunately the $mongodbClientId, which is essentially a reference to a configured connection, can be shared across query-scripts in the database. The $mongodbClientId can be stored as a value in a document in the database and be used by each xquery.

Tip: Since eXist-2.2 it is possible to execute scripts automatically during eXist-db startup. Check conf.xml for details.

###Bucket vs Collection In MongoDB, documents are (logically) stored in collections, compare this to storing files in directories on a filesystem.

In GridFS, documents are distributed over buckets, which are not collections, but.... Under the hood for GridFS two collections are used for each bucket: one for file information and one to store file fragments. See MongoDB manual.

Clone this wiki locally