generated from Arquisoft/lomap_0
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Arquisoft/develop
Develop
- Loading branch information
Showing
68 changed files
with
60,705 additions
and
12,708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// MongoDB Playground | ||
// To disable this template go to Settings | MongoDB | Use Default Template For Playground. | ||
// Make sure you are connected to enable completions and to be able to run a playground. | ||
// Use Ctrl+Space inside a snippet or a string literal to trigger completions. | ||
|
||
// PRUEBA DE INSERCIONES EN LA BASE DE DATOS --> OTRA MANERA INTERESANTE DE REALIZAR INSERCIONES | ||
|
||
// Select the database to use. | ||
use('mongodbVSCodePlaygroundDB'); | ||
|
||
// The drop() command destroys all data from a collection. | ||
// Make sure you run it against the correct database and collection. | ||
db.sales.drop(); | ||
|
||
// Insert a few documents into the sales collection. | ||
db.sales.insertMany([ | ||
{ '_id': 1, 'item': 'abc', 'price': 10, 'quantity': 2, 'date': new Date('2014-03-01T08:00:00Z') }, | ||
{ '_id': 2, 'item': 'jkl', 'price': 20, 'quantity': 1, 'date': new Date('2014-03-01T09:00:00Z') }, | ||
{ '_id': 3, 'item': 'xyz', 'price': 5, 'quantity': 10, 'date': new Date('2014-03-15T09:00:00Z') }, | ||
{ '_id': 4, 'item': 'xyz', 'price': 5, 'quantity': 20, 'date': new Date('2014-04-04T11:21:39.736Z') }, | ||
{ '_id': 5, 'item': 'abc', 'price': 10, 'quantity': 10, 'date': new Date('2014-04-04T21:23:13.331Z') }, | ||
{ '_id': 6, 'item': 'def', 'price': 7.5, 'quantity': 5, 'date': new Date('2015-06-04T05:08:13Z') }, | ||
{ '_id': 7, 'item': 'def', 'price': 7.5, 'quantity': 10, 'date': new Date('2015-09-10T08:43:00Z') }, | ||
{ '_id': 8, 'item': 'abc', 'price': 10, 'quantity': 5, 'date': new Date('2016-02-06T20:20:13Z') }, | ||
]); | ||
|
||
// Run a find command to view items sold on April 4th, 2014. | ||
db.sales.find({ date: { $gte: new Date('2014-04-04'), $lt: new Date('2014-04-05') } }); | ||
|
||
// Build an aggregation to view total sales for each product in 2014. | ||
const aggregation = [ | ||
{ $match: { date: { $gte: new Date('2014-01-01'), $lt: new Date('2015-01-01') } } }, | ||
{ $group: { _id: '$item', totalSaleAmount: { $sum: { $multiply: [ '$price', '$quantity' ] } } } } | ||
]; | ||
|
||
// Run the aggregation and open a cursor to the results. | ||
// Use toArray() to exhaust the cursor to return the whole result set. | ||
// You can use hasNext()/next() to iterate through the cursor page by page. | ||
db.sales.aggregate(aggregation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MONGODB = "mongodb+srv://lomap:12345@lomap-es3b.fsvk8vk.mongodb.net/Lomap-es3b?retryWrites=true&w=majority" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const mongoose = require('mongoose') | ||
|
||
const { MONGODB, MONGODB_ATLAS_TEST, NODE_ENV } = process.env // saca del .env la ruta a la base de datos | ||
|
||
//const connectionString = NODE_ENV === 'test' ? MONGODB_ATLAS_TEST : MONGODB_ATLAS | ||
|
||
const connectionString = MONGODB // el enlace a la base de datos | ||
|
||
if (!connectionString) { | ||
console.error('Yoy must define your connection string') | ||
} | ||
|
||
// Realiza la conexion con la base de datos | ||
const dbConnection = async () => { | ||
try { | ||
mongoose.set("strictQuery", false) | ||
await mongoose.connect(connectionString), { // se conecta con el mongoose | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
useCreateIndex: true, | ||
useFindAndModify: false | ||
} | ||
// en caso de conectar correctamente con la base de datos | ||
console.log('Database online succesfully') | ||
} catch (err) { | ||
console.log(err) | ||
throw new Error('Cannot connect to the database ') | ||
} | ||
|
||
process.on('uncaughtException', error => { | ||
console.error(error) | ||
mongoose.disconnect() | ||
}) | ||
} | ||
module.exports = { dbConnection } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const { Schema, model } = require('mongoose') | ||
|
||
// Esquema para la base de datos y el json | ||
const PlaceSchema = Schema( | ||
{ | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
direction: { | ||
type: String, | ||
required: true | ||
}, | ||
latitude: { | ||
type: Number, | ||
required: true | ||
}, | ||
longitud: { | ||
type: Number, | ||
required: true | ||
}, | ||
comments: { // Los comentarios igual conviene sacarlos de otro apartado de la base de datos | ||
type: String, | ||
required: true | ||
}, | ||
photoLink: { | ||
type: [String], | ||
reguired: true | ||
} | ||
}, | ||
|
||
{ | ||
timestamps: true | ||
} | ||
) | ||
|
||
// Esquema temporal para ver como seria el de los pods | ||
const PodSchema = Schema( | ||
{ | ||
id: { | ||
type: String, | ||
required: true | ||
}, | ||
ratings: [{ // temporal para pruebas | ||
rating1: String, | ||
rating2: String, | ||
rating3: String | ||
}] | ||
}, | ||
|
||
{ | ||
timestamps: true | ||
} | ||
) | ||
|
||
PlaceSchema.methods.toJSON = function () { | ||
const { __v, _id, ...place } = this.toObject() | ||
place.uid = _id | ||
return place | ||
} | ||
|
||
module.exports = model('Place', PlaceSchema) |
Oops, something went wrong.