server/db/mongodb/schema.md
tinodeusersStores user accounts
Fields:
_id user id, primary keycreatedat timestamp when the user was createdupdatedat timestamp when user metadata was updatedaccess user's default access level for peer-to-peer topics
auth, anon default permissions for authenticated and anonymous userspublic application-defined datastate account state: normal (ok), suspended, soft-deletedstateat timestamp when the state was last updated or NULLlastseen timestamp when the user was last onlineuseragent client User-Agent used when last onlinetags unique strings for user discoverydevices client devices for push notifications
deviceid device registration IDplatform device platform string (iOS, Android, Web)lastseen last logged inlang device language, ISO codeIndexes:
_id primary keytags multikey-index (indexed array)deletedat indexdeviceids multikey-index of push notification tokensSample:
{
"access": {
"anon": 0 ,
"auth": 47
} ,
"createdat": "2019-10-11T12:13:14.522Z" ,
"state": 0,
"stateat": null ,
"devices": null ,
"_id": "7yUCHniegrM" ,
"lastseen": "2019-10-11T12:13:14.522Z" ,
"public": {
"fn": "Alice Johnson" ,
"photo": {
"data": Binary('/9j/4AAQSkZJRgAB...'),
"type": "jpg"
}
} ,
"state": 1 ,
"tags": [
"email:[email protected]" ,
"tel:17025550001"
] ,
"updatedat": "2019-10-11T12:13:14.522Z",
"useragent": "TinodeWeb/0.13 (MacIntel) tinodejs/0.13"
}
authStores authentication secrets
Fields:
_id unique string which identifies this record, primary key; defined as "authentication scheme':'some unique value per scheme"userid ID of the user who owns the recordsecret shared secret, for instance bcrypt of passwordauthLvl authentication levelexpires timestamp when the records expiresIndexes:
_id primary keyuserid indexSample:
{
"_id": "basic:alice" ,
"authLvl": 20 ,
"expires": "2019-10-11T12:13:14.522Z" ,
"secret": Binary('/9j/RgAB...'),
"userid": "7yUCHniegrM"
}
topicsThe table stores topics.
Fields:
_id name of the topic, primary keycreatedat topic creation timeupdatedat timestamp of the last change to topic metadataaccess stores topic's default access permissions
auth, anon permissions for authenticated and anonymous users respectivelyowner ID of the user who owns the topicpublic application-defined datastate topic state: normal (ok), suspended, soft-deletedstateat timestamp when the state was last updated or NULLseqid sequential ID of the last messagedelid topic-sequential ID of the deletion operationusebt currently unusedIndexes:
_id primary keyowner indextags multikey indexSample:
{
"access": {
"anon": 64 ,
"auth": 64
} ,
"delid": 0,
"createdat": "2019-10-11T12:13:14.522Z",
"lastmessageat": "2019-10-11T12:13:14.522Z" ,
"id": "p2pavVGHLCBbKrvJQIeeJ6Csw" ,
"owner": "v2JyG4OLSoA" ,
"public": {
"fn": "Travel, travel, travel" ,
"photo": {
"data": Binary('/9j/RgAB...') ,
"type": "jpg"
}
} ,
"seqid": 14,
"state": 0,
"stateat": null,
"updatedat": "2019-10-11T12:13:14.522Z" ,
"usebt": false
}
subscriptionsThe table stores relationships between users and topics.
Fields:
_id used for object retrievalcreatedat timestamp when the user was createdupdatedat timestamp when user metadata was updateddeletedat currently unusedreadseqid id of the message last read by the userrecvseqid id of the message last received by user devicedelid topic-sequential ID of the soft-deletion operationtopic name of the topic subscribed touser subscriber's user IDmodewant access mode that user wants when accessing the topicmodegiven access mode granted to user by the topicprivate application-defined data, accessible by the user onlyIndexes:
_id primary key composed as "topic name':'user ID"user indextopic indexSample:
{
"_id": "grpjajVKrHn0PU:v2JyG4OLSoA" ,
"createdat": "2019-10-11T12:13:14.522Z" ,
"updatedat": "2019-10-11T12:13:14.522Z" ,
"deletedat": null ,
"user": "v2JyG4OLSoA",
"topic": "grpjajVKrHn0PU" ,
"recvseqid": 0 ,
"readseqid": 0 ,
"modewant": 47 ,
"modegiven": 47 ,
"private": "Kirgudu" ,
"state": 0
}
messagesThe table stores {data} messages
Fields:
_id currently unused, primary keycreatedat timestamp when the message was createdupdatedat initially equal to CreatedAt, for deleted messages equal to DeletedAtdeletedfor array of user IDs which soft-deleted the message
delid topic-sequential ID of the soft-deletion operationuser ID of the user who soft-deleted the messagefrom ID of the user who generated this messagetopic which received this messageseqid messages ID - sequential number of the message in the topichead message headersattachments denormalized IDs of files attached to the messagecontent application-defined message payloadIndexes:
_id primary keySample:
{
"_id": "LLXKEe9W4Bs" ,
"createdat": "2019-10-11T12:13:14.522Z" ,
"updatedat": "2019-10-11T12:13:14.522Z",
"deletedfor": [
{
"delid": 1 ,
"user": "wTI0jO9rEqY"
}
] ,
"seqid": 3 ,
"topic": "p2pJhbJnya8z5PBMjSM72sSpg",
"from": "wTI0jO9rEqY" ,
"head": {
"mime": "text/x-drafty"
} ,
"content": {
"fmt": [
{
"len": 6 ,
"tp": "ST"
}
] ,
"txt": "Hello!"
}
}
dellogThe table stores records of message deletions
Fields:
_id currently unused, primary keycreatedat timestamp when the record was createdupdatedat timestamp equal to CreatedAtdelid topic-sequential ID of the deletion operation.deletedfor ID of the user for soft-deletions, blank string for hard-deletionstopic affected topicseqidranges array of ranges of deleted message IDs (see messages.seqid)Indexes:
_id primary keytopic_delid compound index ["Topic", "DelId"]Sample:
{
"_id": "9LfrjW349Rc",
"createdat": "2019-10-11T12:13:14.522Z",
"updatedat": "2019-10-11T12:13:14.522Z",
"topic": "grpGx7fpjQwVC0",
"delid": 18,
"deletedfor": "xY-YHx09-WI",
"seqidranges": [
{
"low": 20,
"hi": 25
}
]
}
credentialsThe tables stores user credentials used for validation.
_id credential, primary keycreatedat timestamp when the record was createdupdatedat timestamp when the last validation attempt was performed (successful or not).method validation methoddone indicator if the credential is validatedresp expected validation responseretries number of failed attempts at validationuser id of the user who owns this credentialvalue value of the credentialIndexes:
_id Primary key composed either as user:method:value for unconfirmed credentials or as method:value for confirmed.user IndexSample:
{
"Id": "tel:+17025550001",
"CreatedAt": "2019-10-11T12:13:14.522Z",
"UpdatedAt": "2019-10-11T12:13:14.522Z",
"Method": "tel" ,
"Done": true ,
"Resp": "123456" ,
"Retries": 0 ,
"User": "k3srBRk9RYw" ,
"Value": "+17025550001"
}
fileuploadsThe table stores records of uploaded files. The files themselves are stored outside of the database.
_id unique user-visible file name, primary keycreatedat timestamp when the record was createdupdatedat timestamp of when th upload has cmpleted or faileduser id of the user who uploaded this file.location actual location of the file on the server.mimetype file content type as a Mime string.size size of the file in bytes. Could be 0 if upload has not completed yet.usecount count of messages referencing this file.status upload status: 0 pending, 1 completed, -1 failed.Indexes:
_id file name, primary keyuser indexusecount indexSample:
{
"_id": "sFmjlQ_kA6A" ,
"createdat": "2019-10-11T12:13:14.522Z" ,
"updatedat": "2019-10-11T12:13:14.522Z" ,
"location": "uploads/sFmjlQ_kA6A" ,
"mimetype": "image/jpeg" ,
"size": 54961090 ,
"usecount": 3,
"status": 1 ,
"user": "7j-RR1V7O3Y"
}