【问题标题】:Comparing ObjectId's using redis and mongodb比较 ObjectId 使用 redis 和 mongodb
【发布时间】: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


【解决方案1】:

确保trim你的string_of_objectid

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-01
    • 1970-01-01
    • 2011-10-17
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多