0

This is the schema of my database table 'users'

{
   "_id": {
    "$oid": "572255b0dad7d9781f92d6bd"
   },
   "local": {
       "password": "$2a$08$JMHr7CMBNkFqi1xxFvO9je1w9qi2BP4tR9Z81FsA2N267PNIBD3ma",
       "email": "[email protected]"
   },
   "__v": 0
}

I am trying to remove this from my database using the following code: functions.js:

function deleteUser(finishedEmail){
   try{
     var socket = io.connect('http://127.0.0.1:8080');
     console.log("success");
   } catch(e){
     console.log("fail");
   }
   if(socket !== undefined){
       var email = finishedEmail;
       socket.emit('userDelete',{
         email:email
       })
   }
}

server.js:

    var col2 = db.collection('users');
    socket.on('userDelete',function(data){
        var email = data.email;
        console.log(data.email);
        col2.deleteOne({email: email}, function(){
            console.log("successful deletion");
        });
    });

In my console I receive the logs: "[email protected]" and "successful deletion". But the email is not deleted. What am I doing wrong?

I've tried the following:

col2.deleteOne({local:{email: email}}, function(){
    console.log("successful deletion");
});

col2.deleteOne({email: email}, function(){
    console.log("successful deletion");
});

col2.deleteOne({local.email: email}, function(){
    console.log("successful deletion");
});

1 Answer 1

1

I think in your server.js you have to write -

col2.deleteOne({"local.email": email}, function(){
   console.log("successful deletion");
});
Sign up to request clarification or add additional context in comments.

1 Comment

unfortunately I tried that and it said "Unexpected Token ." , so after the local. So that doesn't work

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.