我想了解为什么会这样:
req.session._id = doc._id;
req.session.id = doc._id;
console.log(typeof req.session._id); // object
console.log(typeof req.session.id); // string
console.log(req.session._id); // 4oqTbA06DcK9cIiU3tnK62Ic.0puZ9uPnIaghMBIQKaIbhIHYzeP8wtS3MXnzpi+yC1c
console.log(req.session.id); // 4fb01ad2ca42e9552d000001
所以,当我想这样做时:
var myID = req.session._id, myIDm = new BSON.ObjectID(myID); // don't bug
var myID = req.session.id, myIDm = new BSON.ObjectID(myID); // bug: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
感谢您告诉我有关此的所有信息!