Detailed analysis of GUID display issues in Mongodb

Detailed analysis of GUID display issues in Mongodb

Find the problem

I recently migrated the storage of a program to Mongodb and discovered a phenomenon: after the Guid type is written, the data read in the program is different from the data displayed by the client tool. A simple example is as follows:

 var doc = new {_id = 1, Value = Guid.Parse("{B63932BB-9688-432B-B3A0-C4AE3FD2696A}") };
 collection.InsertOne(doc.ToBsonDocument());

After writing to the DB, we view it from the client tool:

By comparison, we can find that the displayed value is different from the written form, but the read value is correct. The answer to this question can be found in the official documentation specification:

Official documentation: http://bsonspec.org/spec.html

Mongodb stores uuid as a binary type, and uses a subtype to mark its type as uuid. In the drivers provided for C#, Java, and Python, the subtype is mapped to 3 (Legacy UUID) by default, which is also displayed in the client tool:

In fact, most client tools can also support displaying the Legacy UUID as we wrote it.

Workaround

Although this does not affect the functionality of the program, it often affects our debugging of the program because the string we see at first glance is not in the format in which it was written. A better solution is to store in standard UUID format by default. You only need to set a global configuration:

 BsonDefaults.GuidRepresentation = GuidRepresentation.Standard;

This is much more convenient:

Reference articles:

MongoDB Best Practices for UUID Data

Summarize

The above is the detailed content about the display problem of GUID in Mongodb. For more information about the display problem of GUID in Mongodb, please pay attention to other related articles on 123WORDPRESS.COM!

<<:  Examples of correct use of maps in WeChat mini programs

>>:  Summary of 9 excellent code comparison tools recommended under Linux

Recommend

Optimize MySQL with 3 simple tweaks

I don't expect to be an expert DBA, but when ...

How to install mysql via yum on centos7

1. Check whether MySQL is installed yum list inst...

Detailed steps for running springboot project in Linux Docker

Introduction: The configuration of Docker running...

Similar to HTML tags: strong and em, q, cite, blockquote

There are some tags in XHTML that have similar fu...

How to get/calculate the offset of a page element using JavaScript

question By clicking a control, a floating layer ...

Tutorial on using the frameset tag in HTML

Frameset pages are somewhat different from ordina...

How to install FastDFS in Docker

Pull the image docker pull season/fastdfs:1.2 Sta...

Use VSCode's Remote-SSH to connect to Linux for remote development

Install Remote-SSH and configure it First open yo...

Upgrade Docker version of MySQL 5.7 to MySQL 8.0.13, data migration

Table of contents 1. Back up the old MySQL5.7 dat...

Simple example of HTML checkbox and radio style beautification

Simple example of HTML checkbox and radio style b...

MySQL backup and recovery design ideas

background First, let me explain the background. ...

How to use the dig/nslookup command to view DNS resolution steps

dig - DNS lookup utility When a domain name acces...

How to increase HTML page loading speed

(1) Reduce HTTP requests. (Merge resource files a...

A detailed introduction to Linux file permissions

The excellence of Linux lies in its multi-user, m...

Some notes on installing fastdfs image in docker

1. Prepare the Docker environment 2. Search for f...