Skip to main content

Unarchiving Documents

Unarchive documents - from the Client API

  • To unarchive documents from the Client API, use the PatchByQueryOperation operation,
    which targets one or more documents based on the patch query.

  • You can apply any filtering condition within the query to target only the documents you want to unarchive.

  • Within the patch script, call the archived.unarchive() method to unarchive all documents
    that match the patch query. Example:

The following operation will unarchive ALL archived documents in the Orders collection.

// Define the patch query string
string patchByQuery = @"
// The patch query:
// ================
from Orders
update
{
// The patch script:
// =================
archived.unarchive(this)
}";

// Define the patch operation, pass the patch string
var patchByQueryOp = new PatchByQueryOperation(patchByQuery);

// Execute the operation by passing it to Operations.Send
store.Operations.Send(patchByQueryOp);

Syntax:

archived.unarchive(doc)
ParameterTypeDescription
docobjectThe document to unarchive.

Unarchive documents - from the Studio

  • To unarchive documents from the Studio:
    • Open the Patch view.
    • Enter a patch script that uses the archived.unarchive() method.
    • Execute the patch. Example:

The following patch script, used directly in the Studio, performs the same operation as the Client API example shown above. It will unarchive all archived documents in the Orders collection.

Unarchive documents

  1. Open the Patch view.
  2. Enter the patch script.
  3. Click to execute the patch.
  4. You can test the patch on a sample document before executing the whole operation.
    Learn more in Test patch.

Unarchiving documents with index-based patch queries

  • When running a patch query to unarchive documents over an index,
    you need to consider the index configuration regarding archived documents.

  • If the index is configured to exclude archived documents, the query portion of the patch operation will not match any archived documents - because those documents are not included in the index.
    As a result, no documents will be unarchived by the patch operation.

  • For example, the following patch query uses a dynamic query that creates an auto-index.
    If the Indexing.Auto.ArchivedDataProcessingBehavior configuration key is set to its default ExcludeArchived value, then even if archived documents exist in the Orders collection with ShipTo.Country == 'USA', they will not be matched - because the auto-index does not include them -
    and the patch operation will not unarchive any documents.

string patchByQuery = @"
// This filtering query creates an auto-index:
// ===========================================
from Orders
where ShipTo.Country == 'USA'
update
{
archived.unarchive(this)
}";

var patchByQueryOp = new PatchByQueryOperation(patchByQuery);
store.Operations.Send(patchByQueryOp);

Two possible workarounds are:

  1. Configure the index to include archived documents:
    This ensures archived documents are included in the index and can be matched by the patch query.
    Use this option only if including archived documents in the index aligns with your indexing strategy.

    For auto-indexes:
    Set the Indexing.Auto.ArchivedDataProcessingBehavior configuration key to IncludeArchived.
    For static-indexes:
    Set the Indexing.Static.ArchivedDataProcessingBehavior configuration key to IncludeArchived,
    or - configure the definition of the specific static-index to include archived documents.
    See Archived documents and indexing.

  2. Use a collection query instead of an index query:
    Run a simple collection-based query that does not rely on an index.
    Apply your filtering logic inside the patch script to unarchive only the relevant documents.

    For example:

string patchByQuery = @"
// Perform a collection query:
// ===========================
from Orders as order
update
{
// Filter documents inside the script:
// ===================================
if (order.ShipTo.City == 'New York')
{
archived.unarchive(this)
}
}";

var patchByQueryOp = new PatchByQueryOperation(patchByQuery);
store.Operations.Send(patchByQueryOp);