2016-04-28 34 views
0

這是我的數據庫表的模式,「用戶」無法使用從數據庫中刪除節點JS /的MongoDB/socket.io

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

我試圖從使用下面的代碼我的數據庫中刪除此: 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"); 
     }); 
    }); 

在我的控制檯我收到的日誌:「一個@ a.a「和」成功刪除「。但是電子郵件不會被刪除。我究竟做錯了什麼?

我已經試過如下: - 「意外的標記」

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

我想在你的server.js你必須寫

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

可惜我試過了,它說,所以在當地之後。所以這不起作用 –

+0

對不起,我的壞。我改變了答案。我想它會工作..... –

+0

真棒工作 –