File size: 587 Bytes
cad3e14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { MONGODB_URL, MONGODB_DB_NAME } from '$env/static/private';
import { MongoClient } from 'mongodb';
import type { Conversation } from '$lib/types/Conversation';

const client = new MongoClient(MONGODB_URL, {
	// directConnection: true
});

export const connectPromise = client.connect().catch(console.error);

const db = client.db(MONGODB_DB_NAME);

const conversations = db.collection<Conversation>('conversations');

export { client, db };
export const collections = { conversations };

client.on('open', () => {
	conversations.createIndex({ sessionId: 1, updatedAt: -1 });
});