2011-08-26 23 views
1

你好,我想刪除蒙戈DB特定的輸入...我現在用的是mongolian 客戶端,我很抱歉,我沒有設法掌握尚API ...如何在node-mongolian上使用dropIndex()?

這樣的嘗試失敗

if(req.body.post.del){ 
    posts.dropIndex({_id:req.body.post.del}, function(err){ //this query must be wrong 
     if(err) 
    res.render('blog_edit', {locals:{title:'Failure to delete from DB'}}); //this is what I get... 
     else 
     posts.find({}).toArray(function(err, arr){ 
     if(err) throw err 

     res.render('blog_edit', {locals:{title:'Success!', posts: arr }}); 
    }) 
    }) 
    } 

請提供一些幫助...... 在此先感謝!

回答

0

最後我設法做什麼,我想用remove代替dropIndex,還是出於某種原因索引由_id是不可能的,所以我用標題:

posts.remove({title:req.body.post.del}, function(err){ //this will work 

這是行不通的:

posts.remove({_id:req.body.post.del}, function(err){ //this will NOT work