【发布时间】:2015-06-30 08:48:23
【问题描述】:
我有一个问题,我在网上的研究中找不到任何答案。我在 Node.js 和 Cassandra 中开发一个 Web 应用程序。我目前正在开发一个通知系统,我必须比较两个 uuid 以确保我不会向做出原始操作(引发通知)的人发送通知。
问题是,当我比较两个应该相等的 uuid 时,我总是得到一个错误的值。
这是我目前正在处理的代码示例:
console.log('user_id :', user_id.user_id);
console.log("user id of the current user :", this.user_id);
console.log(user_id.user_id == this.user_id);
console.log(user_id.user_id === this.user_id);
这是结果的显示:
user_id : Uuid: 29f1227d-58dd-4ddb-b0fa-19b7fc02fbe8
user id of the current user : Uuid: 29f1227d-58dd-4ddb-b0fa-19b7fc02fbe8
false
false
user_id : Uuid: c8f9c196-2d63-4cf0-b388-f11bfb1a476b
user id of the current user : Uuid: 29f1227d-58dd-4ddb-b0fa-19b7fc02fbe8
false
false
如您所见,第一个 uuid 应该是相同的。它们是使用 nodejs cassandra 驱动程序中的 uuid 库生成的。 我不明白为什么当我能够在我的 Cassandra 数据库上使用指定的 uuid 发出任何请求时,我无法比较它们。
如果有人可以帮助我,我会很高兴!
【问题讨论】:
-
什么是
typeof user_id.user_id和typeof this.user_id?我打赌它们是(不同的)对象而不是字符串。原因是 id 在输出中以Uuid:为前缀,这可能来自对象的toString()实现。 -
确实 user_id 和 this.user_id 都是不同的对象,这就是为什么简单的 === 不足以比较它们的原因。
标签: node.js cassandra comparison uuid