【发布时间】:2012-07-16 07:35:50
【问题描述】:
我在使用 mongoDB 和 redis 比较 ObjectIds 时遇到了一些问题。
我将 MongoDB 文档作为 JSON 字符串存储在 redis 中,并在从 redis 检索时使用 JSON.parse,但这会将 ObjectIds 转换为字符串,我很难将它们转换回来。
我正在使用带有猫鼬的 NodeJS,并尝试了以下方法:
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
【问题讨论】:
-
收到错误消息时使用的字符串是什么?
-
字符串就像“47cc67093475061e3d95369d”
标签: node.js mongodb redis mongoose