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

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,
@@ -76,16 +77,20 @@ UserSchema.methods.generateAuthToken = function () {
console.log("GENERA TOKEN : ");
var user = this;
var access = 'auth';
var token = jwt.sign({_id: user._id.toHexString(), access}, process.env.SIGNCODE).toString();
var token = jwt.sign({ _id: user._id.toHexString(), access }, process.env.SIGNCODE).toString();
// CANCELLA I PRECEDENTI !
user.tokens = [];
user.tokens.push({access, token});
user.tokens.push({ access, token });
return user.save().then(() => {
//console.log("TOKEN USCITA : " + token)
return token;
});
return user.save()
.then(() => {
//console.log("TOKEN USCITA : " + token)
return token;
})
.catch(err => {
console.log("Error", err.message);
});
};
UserSchema.statics.findByToken = function (token) {
@@ -109,7 +114,7 @@ UserSchema.statics.findByCredentials = function (username, password) {
var User = this;
var pwd = "";
return User.findOne({username: username}).then((user) => {
return User.findOne({ username: username }).then((user) => {
if (!user) {
return null;
}
@@ -131,7 +136,6 @@ UserSchema.statics.findByCredentials = function (username, password) {
};
UserSchema.statics.findByUsername = function (username) {
var User = this;
@@ -155,7 +159,7 @@ UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot)
return User.findOne({
'email': email,
'tokenforgot': tokenforgot,
'date_tokenforgot': { $gte: new Date(ISODate().getTime() - 1000 * 60 * 60 * 4) } , // 4 ore fa!
'date_tokenforgot': { $gte: new Date(ISODate().getTime() - 1000 * 60 * 60 * 4) }, // 4 ore fa!
'idapp': idapp,
});
};
@@ -192,7 +196,7 @@ UserSchema.methods.removeToken = function (token) {
return user.update({
$pull: {
tokens: {token}
tokens: { token }
}
});
};
@@ -213,6 +217,6 @@ class Hero {
}
module.exports = {User, Hero};
module.exports = { User, Hero };