docHistory
Retrieves complete histories for one or more documents
Definition
The docHistory command returns all versions of specified documents.
The docHistory command has the following form:
{
"docHistory":
{
"collection": <string>,
"filter":<document>,
"projection":<document>
}
}
The command accepts the following fields:
Field | Type | Mandatory | Description |
---|---|---|---|
docHistory.collection | string | yes | The target collection |
docHistory.filter | document | yes | A MongoDB compatible filter condition |
docHistory.projection | document | no | A MongoDB compatible projection document |
Output
The returned document contains a subset of the following fields:
Field | Type | Description |
---|---|---|
ok | number | The status of the command. |
docHistory | array | An array of DocHistory Item's. |
DocHistory Item
Field | Type | Description |
---|---|---|
collection | string | The collection which contains the document. |
_id | any | The document id. |
history | document | The document's history. |
history.versions | array | An array of DocHistory Version's. |
DocHistory Version
Field | Type | Description |
---|---|---|
minVersion | number | The version the document started. |
maxVersion | number | The version the document ended. |
status | string | The proof status of the document. |
started | timestamp | The timestamp when the version started. |
ended | timestamp | The timestamp when the version ended. |
document | document | The document content. |
Example
This example returns all versions of the document that contains the string 'Last Will and Testament' in the name attribute and returns just the name and uploadedAt attributes for each document.
> db.runCommand({docHistory:{
... collection:'files_5c6b4735769348aee6f8fd00' ,
... filter:{name:{$regex:"Last Will and Testament"}},
... projection:{name:1,uploadedAt:1}
... }})
{
"ok" : 1,
"docHistory" : [
{
"collection" : "files_5c6b4735769348aee6f8fd00",
"_id" : ObjectId("5c7f46eebe1e3eaea78b1abe"),
"history" : {
"versions" : [
{
"minVersion" : NumberLong(2),
"maxVersion" : NumberLong(5),
"status" : "Valid",
"started" : "2019-03-06 03:05:02",
"ended" : "2019-03-06 03:05:03",
"document" : {
"name" : "Last Will and Testament of John ProvenDocs.pdf",
"uploadedAt" : "2019-03-06T04:05:02.765Z"
}
},
{
"minVersion" : NumberLong(6),
"maxVersion" : NumberLong("9223372036854775807"),
"status" : "Valid",
"started" : "2019-03-06 03:13:27",
"ended" : "2019-03-06 03:13:27",
"document" : {
"name" : "Last Will and Testement of John ProvenDocs.pdf",
"uploadedAt" : "2019-03-06T04:13:27.562Z"
}
}
]
}
}
]
}
Note:
docHistory will return an error if the amount of data returned exceeds the maximum network message size of approximately 64MB. If you encounter this error, you should use either the filter or projection clauses to reduce the amount of data returned.
You can use a projection to reduce the amount of document data returned. For instance, here we suppress all document data using a projection on a non-existent attribute:
db.runCommand({ docHistory: { collection: collectionName, filter: { X 4 }, projection:{nonExistentAttribute:1} }}
If you really need to extract all versions of large documents you can do so using normal queries. If a filter condition is specified on provendb metadata attributes, then these will over-ride the implicit 'current version' filter. So for instance, this query will return all versions of the documents which has an _id of 4, and will return the metadata as well as the user data:
collection.find({'_provendb_metadata':{$exists:true},'_id':4}, {'_provendb_metadata':1});
Updated over 5 years ago