'How put JSON data to MongoDB?

Im beginner on mongo & javascript, i made a approximate code may be to push all API JSON response on my collection db, so i should take the lead with this code to do something that looks like something rather than doing nothing :

The goal of this file is convert to a card all result of JSON api response, but before that i need to store this response

import { defineStore } from "pinia";
import axios from "axios";
import { MongoClient } from 'mongodb'

export const useCardStore = defineStore("cardStore", {
 state: () => ({
  cards: [], 
  }),
  getters:{
     allCards: (state) => state.cards
  },
 actions: {
   async loadCards() {
   try {
    const response = await axios.get("https://api.adzuna.com/....");
    this.cards = response;
    const { data } = response;
    response.data.results.forEach((item) => {
      console.log(item);
      return item.get().then(response => {
        JSON.parse(response.body.text());
        var MongoClient = require('mongodb').MongoClient;
        var url = 'mongodb://localhost:27017/MyCollection';

        MongoClient.connect(url, function(db) {
        
        var myDB = db.db("JobSeeker");
        
        var myobj = [item];
        
          myDB.collection("cardsJobs").insertMany(myobj, function(res) {
          console.log("Number of item inserted: " + res.insertedCount);
          db.close();
        });
      })
     });
    });
  } 
  catch (error) {
    console.log(error);
      }
  },
 },
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source