|
CommonStorage can be seen as an ArmarX interface for MongoDB. It allows to store arbitrary JSON objects in Mongo collections as well as files in GridFS.
Following properties are supported:
As usual, you need to acquire a proxy first:
Then, open a collection. Please note, that fully qualified MongoDB namespace(=dbname.collectionname) must be specified:
Now you can store a document(=MongoDB record):
insert() function will return an auto-generated unique document id in the MongoDB collection. If you have a natural key and would like to use it instead of a generated value, just set "_id" field in JSON.
Updating a document:
This version will search for a document with name="take" and update it using JSON provided. Use update() function to match by document id ("_id" field).
There is also a so-called "upsert" (update-or-insert) function available:
It will update the document with the same id, if present, and insert a new one otherwise.
Querying:
Removing a document by id:
Finally, close a collection when you're done:
You can also find an example code in CommonStorageExample application.
Since constructing and parsing JSON "by hand" is mostly impractical, there is another option available:
Here is a short three-step HOWTO.
Init serializer:
Save a document:
Load a document:
GridFS is standard for storing files in a database, supported by MongoDB. Files are stored on per-database basis, i.e. each Mongo database has its own "filesystem". Inside the filesystem a specific file can be identified by its name or id, but unlike id, name is NOT guaranteed to be unique. Thus to identify a file globally in the scope of MongoDB instance, a pair of (database_name, file_id) is used.
CommonStorage provides basic, "low-level" functions to manage files in GridFS. For advanced functionality including caching and file reference attributes please refer to GridFS files and file reference attributes section.
Some of the most important functions are introduced below.
Store a file:
Get a complete text file into sting buffer:
File size must be smaller than maximal ICE message size (typically 1MB). For large files use the second option described below.
Get a file chunk-by-chunk:
Remove a file: