To make it easier to understand, you can think of MongoDB as a building. Each database contains multiple collections. MongoDB lets you store things (called documents) inside databases. Keep the mongod window running when you want to work with your local MongoDB. You can start MongoDB on your computer with the mongod command. You should get a response similar to the following: mongo - version Starting MongoDB Once you have completed the installation process, try typing mongo -version into your command line. You can install MongoDB by following these instructions ( Mac and Windows). You need to install MongoDB on your computer before you can connect to it. Today, I want to share how to create and connect to a local MongoDB Database. And I like to connect to a database on my computer because it speeds up dev and test-related work. It’s open source and the code is available in Github.I always use MongoDB as a database when I work on an app. Var guidDecoded = new Guid(bytes.Slice(0, bytesWritten).ToArray()).ToString() įinally, if you just need it now without writing code use a Blazor WebAssembly app I made just for this. If (Convert.TryFromBase64String("YOUR_BASE64_STRING_HERE", bytes, out int bytesWritten)) Var bytes = new Span(new byte) //arbitrary number Var base64Encoded = Convert.ToBase64String("YOUR_GUID_HERE") Īnd here is a way to decode a base64 string that contains GUID bytes: Solutionįollows a C# solution which is simple enough, but of course requires to at least copy-paste the code to a project and run it: Worth mentioning here that we were working on this problem with Dean Herringer and he was the first to notice the problem. No matter how many times I attempted to convert the GUID using various online services to its base64 equivalent, I always failed because these services were converting the GUID to base64 as string!Īnd there’s your problem! Encoding a GUID’s bytes is different than encoding GUID’s representative string value. The value you see is actually a base64 encoded string of the GUID value.Īnd everything was cool for years, up until I had to manually debug a situation where I had to connect directly to MongoDB to search for a document based on a GUID I knew. Far from the previous useless sentence though, mind the blue square because this is how MongoDB stores a GUID. The capture above is showing a part of MongoDB compass connected to a beta database with partially real but old data, located locally. Nevertheless, the schema above gave room for some beautiful data like the following image, with some databases and collections ending up having millions of data located in an availability zone probably near you! The schema of the document is not very important other than the fact that the ID should be of type GUID:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |