Exporting Documents as Files
Use the mlcp export
command to export documents in their original format as files on the native filesystem. For example, you can export an XML document as a text file containing XML, or a binary document as a JPG image.
To export documents from a database as files:
Select the files to export. For details, see Filtering Document Exports.
To select documents in one or more collections, set
-collection_filter
to a comma separated list of collection URIs.To select documents in one or more database directories, set
-directory_filter
to a comma separated list of directory URIs.To select documents matching an XPath expression, use
-document_selector
. To use namespace prefixes in the XPath expression, define the prefix binding using-path_namespace
.To select documents matching a query, use
-query_filter
, alone or in combination with one of the other filter options. False positives are possible; for details, see Understanding When Filters Are Accurate.To select all documents in the database, leave
-collection_filter
,-directory_filter
,-document_selector
, and-query_filter
unset.
Set
-output_file_path
to the destination file or directory on the native filesystem.To prettyprint exported XML when using local mode, set
-indented
to true.
Directory names specified with -directory_filter
should end with “/”.
When using -document_selector
to filter by XPath expression, you can define namespace prefixes using the -path_namespace
option. For example:
-path_namespace 'ex1,http://marklogic.com/example,ex2,http://my/ex2' -document_selector '/ex1:elem[ex2:attr > 10]'
Note
Document URIs are URI-decoded before filesystem directories or filenames are constructed for them. For details, see How URI Decoding Affects Output File Names.
For a full list of export options, see Export Command Line Options.
The following example exports selected documents in the database to the native filesystem directory /space/mlcp/export/files
. The directory filter selects only the documents in /plays
.
# Windows users, see Modifying the Example Commands for Windows $ mlcp.sh export -host localhost -port 8000 -username user \ -password password -mode local -output_file_path \ /space/mlcp/export/files -directory_filter /plays/