-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitdb.js
More file actions
33 lines (24 loc) · 824 Bytes
/
initdb.js
File metadata and controls
33 lines (24 loc) · 824 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
31
32
33
"use strict";
// conexión a la BBDD
const dbConnection = require("./lib/connectMongose.js");
const anunciosData = require("./initDB.anuncios.json");
// Carga de modelos
const Anuncios = require("./models/Anuncio.js");
dbConnection.once("open", () => {
main().catch((err) => console.log("Hubo un error", err));
});
async function main() {
// inicializo anuncios
await initAnuncios();
// desconecto BBDD
dbConnection.close();
}
main().catch((err) => console.log("Hubo un error", err));
async function initAnuncios() {
// primero borro lo existente
const vaciado = await Anuncios.deleteMany();
console.log(`Eliminados ${vaciado.deleteCoint} anuncios.`);
// cargo anuncios iniciales
const anuncios = await Anuncios.insertMany(anunciosData);
console.log(`Creados ${anuncios.length} anuncios.`);
}