Oro*_*dan 7 comparison uuid cassandra node.js
我有一个问题,我无法通过网络上的研究找到任何答案.我在Node.js和Cassandra中处理Web应用程序.我目前正在研究通知系统,我必须比较两个uuids,以确保我不会向做出原始操作的人发送通知(这会激发通知).
问题是,当我比较两个应该是等于的uuids时,我总是得到一个假值.
以下是我目前正在处理的代码示例:
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);
Run Code Online (Sandbox Code Playgroud)
以下是结果的显示:
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
Run Code Online (Sandbox Code Playgroud)
如你所见,第一个uuids应该是相同的.它们是使用nodejs cassandra驱动程序中的uuid库生成的.当我能够使用指定的uuid在我的Cassandra数据库上发出任何请求时,我不明白为什么我无法比较它们.
如果有人能帮助我,那将是一件非常愉快的事!
正如 Ary 提到的,内容相同但地址不同,因此比较返回 false。
cassandra-driver 的 UUID 对象提供了一个 equals 函数,该函数比较可用于此目的的 UUID 内容的原始十六进制字符串:
> var uuid1 = uuid.fromString('29f1227d-58dd-4ddb-b0fa-19b7fc02fbe8')
> var uuid2 = uuid.fromString('29f1227d-58dd-4ddb-b0fa-19b7fc02fbe8')
> uuid1 == uuid2
false
> uuid1 === uuid2
false
> uuid1.equals(uuid2)
true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1470 次 |
| 最近记录: |