MongoDb,如何根据某个_id值删除数据
PHPz
PHPz 2017-04-25 09:01:59
0
3
695

根据自带_id值删除老有问题,
javascript collection.remove({_id: ObjectId(id)}, {w:1}, function (err) { db.close() callback(err) })
提示ObjectId未定义,直接写_id:id 删不掉,id为一个字符串

PHPz
PHPz

学习是最好的投资!

reply all(3)
小葫芦

Read the readme document of the official module,
Need to first var ObjectID = require('mongodb').ObjectID;
Then use collection.findAndRemove({_id: new ObjectID(id)}) to do this

Ty80

db.collection.remove({"_id":ObjectId(id)});

刘奇

If the id is a string, you can do this directly

db.collection.remove({"_id":"你的id"});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template