PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

ListVersionsAsync

This function enumerates versions of the specified key in either ascending or descending order specified by an Enum/SortDirection parameter. It can optionally filter the returned versions by minimum and maximum timestamp.

See Also

  • Articles/Data store|Data Stores, an in-depth guide on data structure, management, error handling, etc.

Parameters

Name Type Default Description

key

Key name for the versions to list. If DataStoreOptions/AllScopes was set to true when accessing the data store through DataStoreService/GetDataStore, this key name must be prepended with the original scope as in “scope/key”.

Ascending

(Optional) Enum specifying ascending or descending sort order. Default is ascending.

0

(Optional) Date after which the versions should be listed.

0

(Optional) Date up to which the versions should be listed.

int
0

(Optional) Number of items to be returned in each page.

Returns

Return Type Summary

A DataStoreVersionPages instance that enumerates all the versions of the key as DataStoreObjectVersionInfo instances.


Code Samples


Retrieving DataStore Versions With a Date Filter

The following code sample retrieves all versions after a specified starting time, sorted in ascending order.

local DataStoreService = game:GetService("DataStoreService")

local experienceStore = DataStoreService:GetDataStore("PlayerExperience")

local time = DateTime.fromUniversalTime(year=2020, month=10, day=09, hour=01, min=42)

local listSuccess, pages = pcall(function()
	return experienceStore:ListVersionsAsync("User_1234", nil, time.UnixTimestampMillis)
end)
if listSuccess then
	local items = pages:GetCurrentPage()

	for key, info in pairs(items) do
		print("Key:", key, "; Version:", info.Version, "; Created:", info.CreatedTime, "; Deleted:", info.IsDeleted)
	end
end