Database Indexes
This document provides an overview of all database indexes used in the project, along with their scripts and purposes.
Index Overview
| Index Name | Database | Collection | Fields | Unique | Purpose |
|---|---|---|---|---|---|
unique_processed | adb-accounting | accounting_event | unique (partial), state: "PROCESSED" | Yes | Ensure uniqueness for processed events. |
organisation_account | adb-accounting | ledger_account | organisationId, accountNumber | Yes | Prevent duplicate ledger accounts. |
target_targetId_targetType | adb-accounting | ledger_account | target.targetId, target.targetType | No | Support queries on ledger targets. |
accountNumber_index | adb-accounting | ledger_account | accountNumber | No | Support account-based queries. |
org_targetId | adb-accounting | ledger_auxiliary_account | organisationId, target.targetId | No | Support auxiliary account lookups. |
parent_id | adb-accounting | ledger_auxiliary_account | parent._id | No | Optimize queries on parent accounts. |
posting_date | adb-accounting | domain_object_accounting_entry | postingDate | No | Optimize queries by posting date. |
direction_index | adb-accounting | domain_object_accounting_entry | direction | No | Optimize direction-based queries. |
account_id | adb-accounting | domain_object_accounting_entry | account._id | No | Optimize queries on account IDs. |
parent_account_id | adb-accounting | domain_object_accounting_entry | account.parent._id | No | Optimize queries on parent accounts. |
notifications_ttl | adb-utilities | notifications_ttl | start | No | Automatically expire old notifications. |
unique_key_files | adb-files | files | uniqueKey (partial) | Yes | Ensure file uniqueness where applicable. |
unique_invoices | adb-accounting | invoices | unique (partial) | Yes | Ensure uniqueness for certain invoices. |
invoice_parentId | adb-accounting | invoices | parentId | No | Optimize queries for invoice hierarchies. |
Detailed Index Scripts
accounting_event Collection
db.getSiblingDB('adb-accounting').getCollection('accounting_event').createIndex(
{ "unique": 1 },
{
unique: true,
partialFilterExpression: {
"unique": { $exists: true },
"state": "PROCESSED"
}
}
);
ledger_account Collection
db.getSiblingDB('adb-accounting').getCollection('ledger_account').createIndex(
{ organisationId: 1, accountNumber: 1 },
{ unique: true }
);
db.getSiblingDB('adb-accounting').getCollection('ledger_account').createIndexes([
{ "target.targetId": 1, "target.targetType": 1 },
{ "accountNumber": 1 }
]);
ledger_auxiliary_account Collection
db.getSiblingDB('adb-accounting').getCollection('ledger_auxiliary_account').createIndexes([
{ "organisationId": 1, "target.targetId": 1 },
{ "parent._id": 1 }
]);
domain_object_accounting_entry Collection
db.getSiblingDB('adb-accounting').getCollection('domain_object_accounting_entry').createIndexes([
{ "postingDate": 1 },
{ "direction": 1 },
{ "account._id": 1 },
{ "account.parent._id": 1 }
]);
notifications_ttl Collection
db.getSiblingDB('adb-utilities').getCollection('notifications_ttl').createIndex({ 'start': 1 }, { expireAfterSeconds: 0 });
files Collection
db.getSiblingDB('adb-files').getCollection('files').createIndex(
{ "uniqueKey": 1 },
{
unique: true,
partialFilterExpression: {
"uniqueKey": { $exists: true }
}
}
);
invoices Collection
db.getSiblingDB('adb-accounting').getCollection('invoices').createIndex(
{ "unique": 1 },
{
unique: true,
partialFilterExpression: {
"unique": { $exists: true }
}
}
);
db.getSiblingDB('adb-accounting').getCollection('invoices').createIndex({ parentId: 1 });
"""