0
console.log("check")
 
Email.findOneAndUpdate(
    { _id: req.params.idUser, "sendedEmail.emailId": req.params.idEmail},
    { 
        $set: {
            "sendedEmail.$.isSeen": true
        }
    },
    function(error) {
        if (error) {
            console.log(error);
        }
    }
);

var emailList = await Email.find()

res.send(emailList)

it work fine with localhost, but in vps it doesn't change anything

sorry for my bad english

2
  • 1
    can you share schema of email Commented Nov 23, 2020 at 5:59
  • @MaheshBhatnagar const mongoose = require('mongoose'); var emailSchema = new mongoose.Schema({ subscriberEmail: String, sendedEmail: Array, }, { versionKey: false } ) var Email = mongoose.model('Email', emailSchema, 'emails'); module.exports = Email; Commented Nov 23, 2020 at 6:08

1 Answer 1

1

modify this line: var Email = mongoose.model('Email', emailSchema). Mongoose will make a collection called: 'emails'

const mongoose = require('mongoose');  
var emailSchema = new mongoose.Schema({     subscriberEmail: String,    sendedEmail: Array,     },     {        versionKey: false     } )  
var Email = mongoose.model('Email', emailSchema); 
module.exports = Email;
Try this syntax with findById() method:

updateEmail: (req, res) => {
        let Id = req.params.id;
        Email.findById(Id, (err, res) =>{
            if(err) return res.status(500).send({message: 'Error to find'});        
        }); 

        let update = req.body;
        Email.findByIdAndUpdate(Id, update, {new: true}, (err, EmailUpdated) => {
            if(err) return res.status(500).send({message: 'Error while updating'});
            if(!EmailUpdated) return res.status(404).send({message: 'Email doesnt exist'});
            return res.status(200).send({email: EmailUpdated});
        });
    },

Sign up to request clarification or add additional context in comments.

1 Comment

Its still doesn't change anything, this is my schema after modify const mongoose = require('mongoose'); var emailSchema = new mongoose.Schema({ subscriberEmail: String, sendedEmail: Array, }, { versionKey: false } ) var Email = mongoose.model('Email', emailSchema); module.exports = Email;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.