Browse Source

Adding test data to mongodb

master
Brandon Nolet 1 year ago
parent
commit
6597ecf094
3 changed files with 15 additions and 6 deletions
  1. +1
    -3
      README.md
  2. +1
    -0
      docs/Database Schema.md
  3. +13
    -3
      src/app.js

+ 1
- 3
README.md View File

@@ -12,6 +12,4 @@ npm run prod

# Mirror

This repository is mirrored in [GitLab](https://gitlab.com/Brandonnolet/generalist). This is a private repository for the time being. Please email me at [linuxliaison@fastmail.com](mailto:linuxliaison@fastmail.com) for access if you wish to submit an issue there.

This is a test
This repository is mirrored in [GitLab](https://gitlab.com/Brandonnolet/generalist). This is a private repository for the time being. Please email me at [linuxliaison@fastmail.com](mailto:linuxliaison@fastmail.com) for access if you wish to submit an issue there.

+ 1
- 0
docs/Database Schema.md View File

@@ -18,6 +18,7 @@ Each task has the following schema
* comment: String
* dateCreated: {type: Date, default: Date.now},
* dateDue: Date
* repeating: { Boolean, recurrence: String, Next: Date}


## Categories


+ 13
- 3
src/app.js View File

@@ -4,7 +4,6 @@ const bodyParser = require('body-parser')
const logger = require('morgan')
const MongoClient = require('mongodb').MongoClient
const singleLine = require('single-line-log').stdout

app.use(bodyParser.json())

const dbUrl = 'mongodb://localhost:27017/generalist'
@@ -27,7 +26,7 @@ app.post('/tasks/', (req, res) => {
app.listen(3000, function() {
console.log('Listening on port: ' + this.address().port)
if (process.env.NODE_ENV === 'dev') {
const fs = require('fs')
app.use(logger('dev'))
console.log('Cauting: running in development mode')
console.log('If you wish to keep all collections in the GeneraList database, please press Ctrl+C (10 seconds)')
@@ -35,7 +34,18 @@ app.listen(3000, function() {
MongoClient.connect(dbUrl, { useNewUrlParser: true},function(err, db){
const dbo = db.db('generalist')
dbo.dropDatabase()
console.log('Dropped all collections')
fs.readdir('./test-data/', (err, files) => {
files.forEach(file => {
console.log(file)
fs.readFile(__dirname + '/test-data/' + file, 'UTF-8', (err, data) => {
var json = JSON.parse(data)
json.forEach(element => {
dbo.collection('categories').insertOne(element)
console.log(element)
})
})
})
})
})
}, 10020)
var i = 10


Loading…
Cancel
Save