我在使用 mongoDB 和 redis 比较 ObjectId 时遇到了一些问题。
我将 MongoDB 文档作为 JSON 字符串存储在 Redis 中,并在从 Redis 检索时使用 JSON.parse,但这会将 ObjectId 转换为字符串,我很难将它们转换回来。
我将 NodeJS 与 Mongoose 一起使用,并尝试了以下方法:
mongoose.Types.ObjectId(string_of_objectid)
但是我得到了错误
Argument passed in must be a single String of 12 bytes or a string of 24 hex characters in hex format
最佳答案
确保修剪
您的string_of_objectid
。
关于node.js - 使用 redis 和 mongodb 比较 ObjectId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10402970/