Not everything is added to my DB

I´am fetching data from an API. I want to store that data in my DB.

I know I get 500 objects every fetch- that is standard with this API. But when I run it with an empty DB, does not every object get added to my DB.
As my understanding, when I use async and await, the code does not continue until the code with the await is done. I have added the console output in a comment below.

Inside a crone.scheduale() i do the following with a async callback.

→ fetch the data → using .json() to make it a json.

cron.schedule("*/10 * * * * *", async () => {
  console.log("10 sek har gått");
  try {
    let response = await fetch("", {
      method: "GET",
      headers: {
        "User-Agent": "Oscar Throedsson",
    const data = await response.json();

→ Validate that the response is an array and console.log() length of the array.

console.log("Array? ", Array.isArray(data)); //output: true
    console.log(`Längd: ${data.length}`); //output: 500

→ Create a for of and run every array item in to a schema. array item is objects.

for (const element of data) {
      let event = createNewDocument(element);

→ Next is validating if the object is in the database. Every array item comes with a uniqe id, and I use that to confirm if it exist or not.

const checkEventExistence = await wholeColl.findOne({ _id: }); //using await so the code checks the database before continuing. 

        `4. ${counter}: Comparing: from API ${

        } -> from DB: ${JSON.stringify(checkEventExistence._id)}`
      ); // output: number -> number. To see the comparision. 
      counter++; // output: Helps me keep track on which list item is printed out. 

→ In an if statement, do I check if findOne() returns falsy or truly (null or object). If it is falsy (null) I add the object to my database of truly i dont add it. I use a try catch to see if the save went well or not.

if (!checkEventExistence) {
        //# | save in DB
        try {
          added++; //! | delete when we clean up the code
          console.log(`SAVED - > EventID: ${}`);
        } catch (error) {
          console.error("Error while saving event:", error);
      } else {
        console.log(`NOT SAVED - > EventID: ${}`);
        //! | delete else when we clean up the code
        notAdded++; //! | delete when we clean up the code

Here can you see what my console.logs() and what comes out is not in the correct order…

:arrow_right: 1. From API: 452571
:arrow_right: server | 2. 467: Comparing: from API 454046 → from DB: {“_id”:454046,“datetime”:“2023-10-09T18:22:03.000Z”,“name”:“09 oktober 19:37, Trafikolycka, Umeå”,“summary”:“Brogatan/Storgatan, Väst på stan. En personbil och en cyklist har kolliderat”,“url”:“/aktuellt/handelser/2023/oktober/9/09-oktober-1937-trafikolycka-umea/”,“type”:“Trafikolycka”,“location”:{“name”:“Umeå”,“gps”:“63.825847,20.263035”},“__v”:0}
server | --------------------
server | NOT SAVED - > EventID: 454046

server | --------------------
:arrow_right: server | 1. From API: 454045
:arrow_right: server | 2. 468: Comparing: from API 452571 → from DB: null
server | --------------------
:arrow_right: :warning: server | 2. 469: Comparing: from API 454045 → from DB: {“_id”:454045,“datetime”:“2023-10-09T18:19:14.000Z”,“name”:“09 oktober 20:00, Stöld, Skellefteå”,“summary”:“Under kvällen har polisen larmats till två butiker med anledning av stöld”,“url”:“/aktuellt/handelser/2023/oktober/9/09-oktober-2000-stold-skelleftea/”,“type”:“Stöld”,“location”:{“name”:“Skellefteå”,“gps”:“64.750244,20.950917”},“__v”:0}
server | --------------------
server | NOT SAVED - > EventID: 454045

The 2 is coming after another 2 which mean we have skipped running next object threw my schema (i guess)

 let event = createNewDocument(element);

      //# | validate if the object exist in DB
      console.log("1. From API: ",;

(below) The 2 is missing before we go to number one again. and the saved ID is not the same as the wone from the current element, but the same as “comparing 468” as abow. The saved ID should be the same as the IDE from "from API: … "

server | --------------------
:arrow_right: server | 1. From API: 454043
server | SAVED - > EventID: 452571
:warning: the 2 is missing

server | --------------------
:arrow_right: :warning: vserver | 1. From API: 452570
:arrow_right: ^Cserver | 2. 470: Comparing: from API 454043 → from DB: {“_id”:454043,“datetime”:“2023-10-09T18:00:40.000Z”,“name”:“09 oktober 18:44, Stöld, Sundsvall”,“summary”:“Birsta, polisen larmas till en butik”,“url”:“/aktuellt/handelser/2023/oktober/9/09-oktober-1844-stold-sundsvall/”,“type”:“Stöld”,“location”:{“name”:“Sundsvall”,“gps”:“62.390811,17.306927”},“__v”:0}
server | --------------------
server | NOT SAVED - > EventID: 454043

On :warning: Can you see that number 1 or 2 is repeating it self, after 1 should only 2 come, and after 2 should only 1 come. Which it doesnt.