Unarchiving Documents
-
Archived documents can be unarchived at any time.
-
The archiving feature does Not need to be enabled to unarchive documents.
Any previously archived document can be unarchived, regardless of the feature's current state. -
Do not attempt to unarchive a document by manually removing the
@archived: true
metadata property from the document. This will not clear the internal archived status of the document.
To properly unarchive a document, use thearchived.unarchive()
method as described below. -
In this article:
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.
- Unarchive_documents
- Unarchive_documents_async
- Operation_overload
- Operation_overload_async
// 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);
// Define the patch query string
string patchByQuery = @"
from Orders
update
{
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
await store.Operations.SendAsync(patchByQueryOp);
// Define the patch query string
string patchByQuery = @"
from Orders
update
{
archived.unarchive(this)
}";
// Define the patch operation, pass the patch string
var patchByQueryOp = new PatchByQueryOperation(new IndexQuery()
{
Query = patchByQuery
});
// Execute the operation by passing it to Operations.Send
store.Operations.Send(patchByQueryOp);
// Define the patch query string
string patchByQuery = @"
from Orders
update
{
archived.unarchive(this)
}";
// Define the patch operation, pass the patch string
var patchByQueryOp = new PatchByQueryOperation(new IndexQuery()
{
Query = patchByQuery
});
// Execute the operation by passing it to Operations.Send
await store.Operations.SendAsync(patchByQueryOp);
Syntax:
archived.unarchive(doc)
Parameter | Type | Description |
---|---|---|
doc | object | The 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.
- Open the Patch view.
- Enter the patch script.
- Click to execute the patch.
- 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 defaultExcludeArchived
value, then even if archived documents exist in the Orders collection withShipTo.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:
-
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 toIncludeArchived
.
For static-indexes:
Set the Indexing.Static.ArchivedDataProcessingBehavior configuration key toIncludeArchived
,
or - configure the definition of the specific static-index to include archived documents.
See Archived documents and indexing. -
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);