Alright, here I have a code where I have my Express server, the connection to the database and apparently everything works fine.
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const helmet = require('helmet');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/firulais', { useNewUrlParser: true }, ()=> {
console.log("Connected")
});
//Models
var Users = mongoose.model('Users', {
id:String,
first:String,
last:String,
age:Number,
pass:String,
country:String,
tel:Number,
adm:Boolean
})
var Polls = mongoose.model('Polls', {
id:String,
name:String,
description:String,
yes:Number,
no:Number,
veto:Boolean
})
var a = Users.find({
tel:7862627420
})
console.log(a.tel)
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(helmet());
app.get('/', (req,res)=>{
res.render("index")
})
app.post('/', (req,res)=>{
res.render("index")
})
app.post('/reglas', (req,res)=>{
var tel = req.body.number;
var pass = req.body.password;
})
module.exports = app;
The part that worries me is when I go to look for some data in some collection of the database. I explain. This page that I want to do requires that the user enter their phone number and a password to enter. So I was trying to find the phone number of a user in the collection that I created and for that I use a method called findOne () that passes as a parameter a json with the value I try to locate:
var a = Users.find({
tel:7862627420
})
console.log(a.tel)
and then I try to show it by console that way. This returns an undefined value that I do not want, but rather that I return the number.
I do not know if I gave myself to explain well.