@unchainedshop/core-events
Version:
Event history and tracking module for the Unchained Engine
27 lines (26 loc) • 842 B
JavaScript
import { mongodb } from '@unchainedshop/mongodb';
import { buildDbIndexes } from '@unchainedshop/mongodb';
const EVENTS_TTL_SECONDS = Number(process.env.EVENTS_TTL_SECONDS) || 172800;
export const EventsCollection = async (db) => {
const Events = db.collection('events');
await buildDbIndexes(Events, [
{
index: { _id: 'text', type: 'text' },
options: {
weights: {
_id: 8,
type: 4,
},
name: 'events_fulltext_search',
},
},
]);
await buildDbIndexes(Events, [
{
index: { created: -1 },
options: { expireAfterSeconds: EVENTS_TTL_SECONDS, name: 'created' },
},
{ index: { type: 1 }, options: { name: 'type' } },
]);
return Events;
};