const axios = require('axios'); const fs = require('fs'); const {MongoClient, ObjectId} = require('mongodb') const client = new MongoClient('mongodb://127.0.0.1:27017') const mymongodb = client.db('labfin') const loadFromJson = async () => { let rawdata = fs.readFileSync('mongoDataSave.json'); let data = JSON.parse(rawdata); //console.log(data); await client.connect() const mymongodb = client.db('labfin') console.log('connected!!!!!!!!!11') for(const record of data) { const finalRequests = [] for(const req of record['requests']) { finalRequests.push({ _id: new ObjectId(), date: req['date'], specialization: req['specialization'], education_form: req['education_form'], exam_results: req['exam_results'] }) } const finalResults = [] for(const res of record['exam_results']) { finalResults.push({ _id: new ObjectId(), title: res['title'], results: res['result'] }) } await mymongodb.collection('abiturs').insertOne({ _id: new ObjectId(), first_name: record['first_name'], last_name: record['last_name'], middle_name: record['middle_name'], email: record['email'], password: record['password'], exam_results: finalResults, requests: finalRequests }) } console.log('loaded from json!') } loadFromJson()