Changelog Entry
An entry in the changelog of an object represents a certain action that was undertaken on it.
Every attribute is readable-only.
Attributes
Name | Description | Search |
---|---|---|
batch_id |
ID of the batch operation in which this object was changed (integer, unique) | Number |
operation |
Name of the operation (string): INSERT, UPDATE or DELETE | NotAnalyzed |
schema_version |
Schema version that was active when the change took place (integer) | Number |
time |
Timestamp of the change (Timestamp) | Timestamp |
version |
Version of the object (integer): the _version attribute of the object |
Number |
current_version |
Whether this is the current version of the object (boolean) | Boolean |
user |
User that performed the operation (user (short)) | Number(*) |
groups |
Groups the user belonged to at the time of the operation (array of integers): ref group._id) |
Number |
comment |
Comment (string, optional) | Text |
(*) user.user._id
is searchable as Number
Searching objects using the changelog
The changelog is searchable both using direct queries and nested queries. Normally, you would want to use a nested query. Here’s why:
Mr. White is looking for an object. He knows it is a “picture” and he changed it today (April 17). He therefore uses a query with the conditions:
(1) objecttype is “picture” (2) changelog user is Mr. White (3) changelog operation is UPDATE (4) changelog time is April 17
Now, there are two pictures:
Picture 1
{
"picture": { // matches (1)
"_id": 1,
"_version": 3,
...
},
"_changelog": [
{
"time": "2014-04-15T10:03:06+02:00",
"operation": "INSERT",
"batch_id": 263,
"version": 1,
"schema_version": 35,
"user": {
"_basetype": "user",
"user": {
"_id": 21, // matches (2)
"_generated_displayname": "Mr. White"
}
},
"current_version": false
},
{
"time": "2014-04-16T10:03:07+02:00",
"operation": "UPDATE", // matches (3)
"batch_id": 264,
"version": 2,
"schema_version": 35,
"user": {
"_basetype": "user",
"user": {
"_id": 36,
"_generated_displayname": "Mr. Blue"
}
},
"current_version": false
},
{
"time": "2014-04-17T10:03:09+02:00", // matches (4)
"operation": "UPDATE", // matches (3)
"batch_id": 265,
"version": 3,
"schema_version": 35,
"user": {
"_basetype": "user",
"user": {
"_id": 21, // matches (2)
"_generated_displayname": "Mr. White"
}
},
"current_version": true
}
],
...
}
Picture 2
{
"picture": { // matches (1)
"_id": 1,
"_version": 2,
...
},
"_changelog": [
{
"time": "2014-04-17T12:03:06+02:00", // matches (4)
"operation": "INSERT",
"batch_id": 263,
"version": 1,
"schema_version": 35,
"user": {
"_basetype": "user",
"user": {
"_id": 21, // matches (2)
"_generated_displayname": "Mr. White"
}
},
"current_version": false
},
{
"time": "2014-04-17T15:03:07+02:00", // matches (4)
"operation": "UPDATE", // matches (3)
"batch_id": 264,
"version": 2,
"schema_version": 35,
"user": {
"_basetype": "user",
"user": {
"_id": 36,
"_generated_displayname": "Mr. Blue"
}
},
"current_version": true
}
],
...
}
Normal query
If Mr. White uses a normal query like this…
{
"objecttype": [ "picture" ], // (1)
"search": [
{
"type": "in", // (2)
"field": [ "_changelog.user.user._id" ],
"in": [ 21 ]
},
{
"type": "in", // (3)
"field": [ "_changelog.operation" ],
"in": [ "UPDATE" ]
},
{ // (4)
"type": "range",
"field": "_changelog.time",
"from": "2014-04-17T00:00",
"to": "2014-04-17T23:59"
}
]
}
… the result will be pictures 1 AND 2. The problem is that the query matches all conditions across all changelog entries. In order to specify that all conditions should be matched in one particular entry, Mr. White should use a nested query:
Nested query
{
"objecttype": [ "picture" ], // (1)
"search": [
{
"type": "nested",
"path": "_changelog", // in one entry of _changelog
"search": [
{
"type": "in", // (2)
"field": [ "_changelog.user.user._id" ],
"in": [ 21 ]
},
{
"type": "in", // (3)
"field": [ "_changelog.operation" ],
"in": [ "UPDATE" ]
},
{ // (4)
"type": "range",
"field": "_changelog.time",
"from": "2014-04-17T00:00",
"to": "2014-04-17T23:59"
}
]
}
]
}
This query returns only picture 1 because it has a changelog entry (the last one) that matches all conditions.
Usually you want to use a nested query for changelog entries, but sometimes a normal query works, and it is faster. For example, if you need to search for objects that were changed today, or objects that have Mr. White as last editor, you can use a normal query.