5.1 Document Management

The contents of the database can be inspected with the extension function pf:collections(); it returns all XML collections. For each collection, or for the entire database, a list of all XML documents contained in it can be obtained with pf:documents() (see see Metadata Functions).

Similarly, the pf:add-doc() and pf:del-doc() functions allow for adding documents to and deleting documents from an XML database using an XQuery query (see Document Management Functions). Alternatively, you can also add and delete documents with the Administrative GUI (see The Administrative GUI). It provides a simple, yet effective GUI to view all documents in a collection, providing buttons to add and delete documents.

Any query containing an pf:add-doc() or pf:del-doc() is called a document management query. A document management query does not return any value, highly similar to the XQuery Update Facility. However, this family of MonetDB/XQuery extension functions is not considered the same as XQUF update queries. In fact, it is specifically forbidden to mix XQUF updates and document management commands in the same transaction.

This has a technical reason: for MonetDB/XQuery it is difficult to provide atomicity based on two quite different principles, namely write ahead logging (used for updates) and check-pointing (used for document management). This design decision was made to allow efficient bulk import. This means that an pf:add-doc() call directly creates new table images on disk (check-pointing), rather than writing the added XML document(s) first to a log.

Similar to the XQUF syntax of updating function, used to declare a function that performs updates and hence has no return value; we introduce the syntax of document management function, used to declare a user-defined function that performs an pf:add-doc() or pf:del-doc().

declare document management function addFoo($name as xs:string)
{ pf:add-doc($name,$name) };

addFoo("http://monetdb.cwi.nl/XQuery/files/bib.xml")

Note that the above function declaration uses the special keywords document management and does not specify a return type.