Skip to content
Snippets Groups Projects
Commit fe0e5a1c authored by Roy Grönroos's avatar Roy Grönroos
Browse files

Update app to use MongoDB

parent 57fa99d4
No related branches found
No related tags found
No related merge requests found
const mongoose = require('mongoose')
const url = "mongodb+srv://webmod:@cluster0.laazp.mongodb.net/fullstack-persons?retryWrites=true&w=majority"
const url = process.env.MONGODB_URI
mongoose.connect(url)
......
const mongoose = require('mongoose')
// Replace with the URL of your own database. Do not store the password on GitLab!
const url = "mongodb+srv://webmod:<pw>@cluster0.laazp.mongodb.net/fullstack-persons?retryWrites=true&w=majority"
mongoose.connect(url)
const Person = mongoose.model('Person', {
name: String,
number: String
})
if (process.argv.length === 4) {
console.log("Adding person " + process.argv[2] + " number " + process.argv[3] +
" to the directory")
const person = new Person({
name: process.argv[2],
number: process.argv[3]
})
person
.save()
.then(response => {
console.log('person saved!')
mongoose.connection.close()
})
} else if (process.argv.length === 2) {
Person
.find({})
.then(result => {
console.log("puhelinluettelo:")
result.forEach(person => {
console.log(person.name + " " + person.number)
})
mongoose.connection.close()
})
} else {
mongoose.connection.close()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment