📌  相关文章
📜  == 操作不适用于 express 中的 id - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:03.859000             🧑  作者: Mango

代码示例1
Mongoose uses the mongodb-native driver, which uses the custom ObjectID type.
You can compare ObjectIDs with the .equals() method.
With your example, results.userId.equals(AnotherMongoDocument._id).
The ObjectID type also has a toString() method, if you wish to store a stringified version of the ObjectID in JSON 
format, or a cookie.

If you use ObjectID = require("mongodb").ObjectID (requires the mongodb-native 
library) you can check if results.userId is a valid identifier with 
  results.userId instanceof ObjectID.