简体   繁体   English

将 mongodb bindata uuid 转换为 sql 服务器唯一标识符

[英]convert mongodb bindata uuid to sql server uniqueidentifier

How to convert MongoDB bindata uuid to sql server uniqueidentifier?如何将 MongoDB bindata uuid 转换为 sql 服务器唯一标识符?

I have { _id: BinData(3,"FOUmkwBNAEyvGcFpJRpJfA==")} in MongoDB(db.version(): 4.4.11)我有 { _id: BinData(3,"FOUmkwBNAEyvGcFpJRpJfA==")} 在 MongoDB(db.version(): 4.4.11)

I can convert it to UUID by the following command:我可以通过以下命令将其转换为 UUID:

db.getCollection('mycollection').findOne({ _id: BinData(3,"FOUmkwBNAEyvGcFpJRpJfA==")})._id.hex() db.getCollection('mycollection').findOne({ _id: BinData(3,"FOUmkwBNAEyvGcFpJRpJfA==")})._id.hex()

14e52693004d004caf19c169251a497c 14e52693004d004caf19c169251a497c

The MS SQL service (Microsoft SQL Server 2017 on Windows Server 2012 R2) uniqueidentifier is MS SQL服务(Microsoft SQL Server 2017 on Windows Server 2012 R2)uniqueidentifier是

9326E514-4D00-4C00-AF19-C169251A497C 9326E514-4D00-4C00-AF19-C169251A497C

Question How to verify the MongoDB bindata uuid { _id: BinData(3,"FOUmkwBNAEyvGcFpJRpJfA==")} to sql server uniqueidentifier: 9326E514-4D00-4C00-AF19-C169251A497C?问题 如何验证 MongoDB bindata uuid { _id: BinData(3,"FOUmkwBNAEyvGcFpJRpJfA==")} 到 sql 服务器 uniqueidentifier: 9326E514-4D00-4C00-AF19-C169251A497C?

A SQL Server Uniqueidentifier doesn't have to follow any of the UUID versions, so any 16 bytes can be converted into a uniqueidentifier. SQL Server Uniqueidentifier 不必遵循任何 UUID 版本,因此任何 16 个字节都可以转换为 uniqueidentifier。 And you can cast to uniqueidentifier either from char or from binary types, eg:您可以从 char 或二进制类型转换为 uniqueidentifier,例如:

select cast(0x14e52693004d004caf19c169251a497c as uniqueidentifier)

outputs产出

9326E514-4D00-4C00-AF19-C169251A497C

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM