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

View File

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