Resolved error Unknown modifier: $pushAll

adding this:

 mongoose.plugin(schema => { schema.options.usePushEach = true });
This commit is contained in:
Paolo Arena
2018-12-27 18:13:43 +01:00
parent a0d39dcbb1
commit 06cd4b8f0d
4 changed files with 66 additions and 36 deletions

10
.env.production Normal file
View File

@@ -0,0 +1,10 @@
DATABASE =FreePlanet
TEST_ATTIVO=1
PORT=3000
URLBASE_APP1=http://freeplanet.app
PORT_APP1=80
DOMAIN=mongodb://localhost:27017/
SIGNCODE=abc123
EMAIL_FROM=perseo774.un@gmail.com
EMAIL_PW=passpao1UNOK
SEND_EMAIL="0"

17
ecosystem.config.js Normal file
View File

@@ -0,0 +1,17 @@
module.exports = {
apps : [
{
name: "FreePlanetServerSide",
script: "./server/server.js",
watch: true,
env: {
"PORT": 3000,
"NODE_ENV": "development"
},
env_production: {
"PORT": 8080,
"NODE_ENV": "production",
}
}
]
}

View File

@@ -1,4 +1,3 @@
var bcrypt = require('bcrypt'); var bcrypt = require('bcrypt');
const mongoose = require('mongoose'); const mongoose = require('mongoose');
@@ -6,6 +5,8 @@ const validator = require('validator');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const _ = require('lodash'); const _ = require('lodash');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => { schema.options.usePushEach = true });
var UserSchema = new mongoose.Schema({ var UserSchema = new mongoose.Schema({
email: { email: {
@@ -14,10 +15,10 @@ var UserSchema = new mongoose.Schema({
trim: true, trim: true,
minlength: 1, minlength: 1,
unique: true, unique: true,
validate: { /*validate: {
validator: validator.isEmail, validator: validator.isEmail,
message: '{VALUE} is not a valid email' message: '{VALUE} is not a valid email'
} }*/
}, },
idapp: { idapp: {
type: Number, type: Number,
@@ -82,9 +83,13 @@ UserSchema.methods.generateAuthToken = function () {
user.tokens = []; user.tokens = [];
user.tokens.push({ access, token }); user.tokens.push({ access, token });
return user.save().then(() => { return user.save()
.then(() => {
//console.log("TOKEN USCITA : " + token) //console.log("TOKEN USCITA : " + token)
return token; return token;
})
.catch(err => {
console.log("Error", err.message);
}); });
}; };
@@ -131,7 +136,6 @@ UserSchema.statics.findByCredentials = function (username, password) {
}; };
UserSchema.statics.findByUsername = function (username) { UserSchema.statics.findByUsername = function (username) {
var User = this; var User = this;

View File

@@ -81,7 +81,6 @@ app.post(process.env.LINKVERIF_REG, (req, res) => {
}); });
// Faccio richiesta di una Nuova Password // Faccio richiesta di una Nuova Password
app.post(process.env.LINK_REQUEST_NEWPASSWORD, (req, res) => { app.post(process.env.LINK_REQUEST_NEWPASSWORD, (req, res) => {
var body = _.pick(req.body, ['idapp', 'email']); var body = _.pick(req.body, ['idapp', 'email']);
@@ -127,14 +126,14 @@ app.post(process.env.LINK_UPDATE_PASSWORD, (req, res) => {
user.password = password; user.password = password;
// Crea token // Crea token
token = user.generateAuthToken(); user.generateAuthToken().then(token => {
user.tokenforgot = ''; // Svuota il tokenforgot perché non ti servirà più... user.tokenforgot = ''; // Svuota il tokenforgot perché non ti servirà più...
// Salva lo User // Salva lo User
user.save().then(() => { user.save().then(() => {
res.header('x-auth', token).send(user); // Ritorna il token di ritorno res.header('x-auth', token).send(user); // Ritorna il token di ritorno
}); });
})
} }
}).catch((e) => { }).catch((e) => {
console.log(e); console.log(e);