0

我在使用 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
4

1 回答 1

1

确保trim您的string_of_objectid.

于 2012-05-07T23:11:29.687 回答