Join us on the demo, while our product experts provide a detailed walkthrough of our enterprise platform.

logoAsync

The latest news in the world of engineering.

Identity and Access Management (IAM), including security and customer experience.

Visit Blog
Fuel

Grow your business to millions.Engage and retain your customers.

Visit Blog

GUID Query Through Mongo Shell

If you have stored a GUID through the C# driver to mongoDB and now you want to run a query by GUID, you can't query directly because mongoDB doesn't recognize…

Govind Malviya
Govind Malviya
February 23, 2015
1 min read

Free, Secure and Trusted Way to Authenticate Your Visitors

Add login to your website in 5 minutes completely for free!

Free Sign UpNo hidden costs. No credit card needed.

If you have stored a GUID through the C# driver to mongoDB and now you want to run a query by GUID, you can't query directly because mongoDB doesn't recognize GUID so when we query through mongo shell no result will be returned. To use the power of mongo shell for querying data on mongo by GUID, you should follow these steps.

1. Convert GUID data to Base64

Convert you GUID data to base64 , you can use any online tool for this. I use this http://guid-convert.appspot.com/

So suppose your GUID is: 00112233-4455-6677-8899-aabbccddeeff

Then the base 64 version will be: MyIRAFVEd2aImaq7zN3u/w==

2. Query by BinData object in mongo shell

db.Users.find({"useUniqueId": new BinData(3,"MyIRAFVEd2aImaq7zN3u/w==")}).limit(1)

Actually BinData constructor takes 2 parameters:

New BinData(subtype,data)

  • Subtype: represent subdata type like we pass 3 for UUID or GUID
  • Data: base64 encoded string data

mongoDB's C# driver stores data to mongo by converting it into binary data rather than string.



LoginRadius Docs

Implement Authentication in Minutes

click here

Most Popular Tags

EngineeringJavaScriptReactAuthenticationNodeJsCSSSecurityC#JWTOAuth

Do you want a free authentication solution?

Add the world's most secure, reliable and easy to implement user authentication solution on your applications at $0Get Started Free

Govind Malviya

Govind Malviya

Director of Product Development @ LoginRadius. Likes tech, reading/writing, founding things.

View Profile

    TOC

Try a Modern Authentication Solution

$0/ month

Free Sign Up
  • 7,000 Monthly Active Users
  • 1 Web or Mobile App
  • Email/Password Login
  • 3 Social Login Providers
  • User Data Storage
  • Transactional Email Template
  • Customizable Login Interfaces