-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (25 loc) · 682 Bytes
/
script.js
File metadata and controls
30 lines (25 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { Post } = require("./models/post");
const a = async () => {
const posts = await Post.find({}, { _id: 1 }).lean();
let queries = [];
let createcomm = [];
for (let i = 1; i < 101; i++) {
queries.push(
new Promise((res, rej) => {
return fetch(`https://jsonplaceholder.typicode.com/posts/${i}/comments`)
.then((data) => data.json())
.then((data) => res(data));
})
);
}
let result = await Promise.all(queries);
result.map((comms, index) => {
comms.map((m) => {
delete m["id"];
m["postId"] = posts[index]._id;
createcomm.push(m);
});
});
return createcomm;
};
module.exports = { a };