1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import process from "node:process";
export const readMediumPosts = (async () => {
const { initDatabase } = await import("npm:mongo-http");
const articlesDatabase = initDatabase({
appId: process.env.MONGODB_ARTICLES_APP_ID,
apiKey: process.env.MONGODB_ARTICLES_API_KEY,
databaseName: "medium",
});
const results = await articlesDatabase.collection("articles").find({
filter: { categories: { $in: ["javascript", "typescript"] } },
projection: {
_id: 0,
creator: 1,
title: 1,
pubDate: 1,
guid: 1,
categories: 1,
},
sort: { isoDateTs: -1 },
limit: 30,
});
return results;
})();