Skip to content
Snippets Groups Projects
Commit 80d2ab87 authored by Martin Lehoux's avatar Martin Lehoux
Browse files

migrate from old db

parent 365dea20
No related branches found
No related tags found
No related merge requests found
const mongoose = require('mongoose');
const Client = require("./models/client");
const Produit = require("./models/clients");
mongoose.connect('mongodb://localhost/bonober', err => {
if (err) console.error(err);
else require("mongodb").MongoClient.connect('mongodb://localhost:27017', (err, client) => {
if (err) console.error(err);
else {
const db = client.db("bonober-prod");
db.collection("customers").find({}).toArray((err, customers) => {
customers.forEach(customer => {
Client.create({
prenom: customer.firstName,
nom: customer.lastName,
promotion: customer.promoYear,
membre: customer.isNegativeAllowed,
solde: customer.balance
});
});
});
db.collection('products').find({}).toArray((err, products) => {
products.forEach(product => {
Produit.create({
nom: product.name,
prixUnitaire: product.unitPrice,
categorie: product.category
});
});
});
}
}
);
});
\ No newline at end of file
......@@ -16,6 +16,7 @@
"express": "^4.16.4",
"express-fileupload": "^1.1.2-alpha.1",
"express-session": "^1.15.6",
"mongodb": "^3.1.13",
"mongoose": "^5.4.17",
"morgan": "^1.9.1",
"nodemon": "^1.18.10",
......
......@@ -1819,7 +1819,7 @@ mongodb-core@3.1.11:
optionalDependencies:
saslprep "^1.0.0"
mongodb@3.1.13, mongodb@~3.1.8:
mongodb@3.1.13, mongodb@^3.1.13, mongodb@~3.1.8:
version "3.1.13"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.1.13.tgz#f8cdcbb36ad7a08b570bd1271c8525753f75f9f4"
integrity sha512-sz2dhvBZQWf3LRNDhbd30KHVzdjZx9IKC0L+kSZ/gzYquCF5zPOgGqRz6sSCqYZtKP2ekB4nfLxhGtzGHnIKxA==
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment