import { mongoConnect } from '$lib/database/mongo.server';

export async function load({ params }) {
	const tag = params.tag;
	const db = await mongoConnect();
	const query = {
		tags: {
			$in: [tag]
		}
	};
	const col = db.db('fredboniface').collection('posts');
	const res = col.find(query);
	const posts = await res.toArray();

	return { data: JSON.stringify(posts), tag: tag };
}
