Skip to content
Studio 3T - The professional GUI, IDE and client for MongoDB
  • Tools
    • Aggregation Editor
    • IntelliShell
    • Visual Query Builder
    • Export Wizard
    • Import Wizard
    • Query Code
    • SQL Query
    • Connect
    • Schema Explorer
    • Compare
    • SQL ⇔ MongoDB Migration
    • Data Masking
    • Task Scheduler
    • Reschema
    • More Tools and Features
  • Solutions
  • Resources
    • Knowledge Base
    • MongoDB Tutorials & Courses
    • Tool/Feature Documentation
    • Reports
    • Case Studies
    • Whitepapers
    • Blog
    • Testimonials
    • Community
  • Contact us
    • Contact
    • Sales Support
    • Feedback and Support
    • Career
    • About Us
  • Store
    • Buy Now
    • Preferred Resellers
    • Team Pricing
  • My License
  • Download
search

Is there a quicker way to query _id values? #Studio3T_AMA

Posted on: 27/10/2021 by DJ Walker-Morgan

Q: Is there a quicker way to query _id values in Studio 3T? I hate typing out the same old query!

Welcome to the latest Studio 3T Ask Manatees Anything – #Studio3T_AMA. Want to know how to use Studio 3T to make your MongoDB life better? Just tweet and use #Studio3T_AMA or email [email protected].

A: It can be so tedious typing out the same old queries for the _id field. It’s the unique id for every document and so it becomes embedded in your daily query life. After a while typing

{ "_id": ObjectId(" the object id goes here") }

becomes second nature to you and you settle in to digging through various documents. But there is another way.

Enter Studio 3T Query _id shortcuts. 

If you write a string, date, or number into the query field of the Collection Tab and hit return, Studio 3T will look at it, try and determine what type it is and create an id filter for that on the spot.

ObjectId _id

Let’s start with ObjectId; the default type for _id fields. If you enter the hexadecimal number that conforms to an ObjectId:

Query _id with an ObjectId _id shortcut

…and then hit return, it expands out to:

An ObjectId _id shortcut expanded

That’s wrapped the value in an ObjectId, complete with quotes and all inside a { “_id”: … }:

{ "_id" : ObjectId("57d28452ed5d4d54e8686f9d") }

Because you may be copying these values from code or configuration files, Studio 3T also recognises an ObjectId if it has single or double quotes around it.

UUID _id

Next up, UUIDs. UUIDs are an alternative to ObjectIds; they carry less information than an ObjectId, but their unique qualities make them useful as a unique id across systems. They appear as yet another hexadecimal based string, one which can be identified by Studio 3T. That means entering a UUID string

Query _id with A UUID _id shortcut

Hit return and that’s transformed into:

A UUID _id shortcut expanded

Integer _id

Are you old school with your _id field? Using integer values for records. We’re here to help with that too:

Query _id with an Integer _id shortcut

Hit return for a perfectly formed integer id query:

An Integer _id shortcut expanded

Don’t put quotes around this one though because that would force it to be interpreted as a string. Talking of which…

String _id

Not the most common of index types, but if you do use strings for your index, you should know you can put a single or double quoted string in:

Query _id with a String _id shortcut

And after hitting return, you’ll have an _id query using that string:

A String _id shortcut expanded

Wrapping up

The _id shortcut may look simple, but it can save a lot of time if you spend your time looking up records by their _id. It’s a Studio 3T tip everyone should know.


How helpful was this article?
This article was hideous
This article was bad
This article was ok
This article was good
This article was great
Thank you for your feedback!

About The Author

DJ Walker-Morgan

Dj has been around since Commodore had Pets and Apples grew everywhere. With a background in Unix and development, he's been around the technology business writing code or writing content ever since.

Related articles

  • Why can’t I change the _id field? #Studio3T_AMA
  • What is the fastest way to make a database connection? #Studio3T_AMA
  • Lesson 4, Exercise 3: Using Visual Query Builder to query multiple array values
  • The Quickest Way to Change a Field Type in MongoDB
  • Lesson 4, Exercise 1: Using IntelliShell to query single and multiple values in an array

Tags

academy aggregation AMA atlas community connections date tags export features hackolade import intellishell JSON knowledge base migration modelling mongodb mongoodb productivity query regex releases schema security SQL Studio 3T tasks tips updates webinar windows

Browse by MongoDB topic

  • Connecting to MongoDB
  • Database Administration & Security
  • Getting Started with MongoDB
  • Getting Started with Studio 3T
  • Import/Export
  • Job Automation & Scheduling
  • MongoDB Aggregation Framework
  • MongoDB/Studio 3T Workshops
  • Performance
  • Query & CRUD Operations
  • Schema
  • Studio 3T Licensing
  • Support and other resources
  • Working with MongoDB & SQL
  • Working with MongoDB Atlas

Studio 3T

MongoDB Enterprise Certified Technology PartnerSince 2014, 3T has been helping thousands of MongoDB developers and administrators with their everyday jobs by providing the finest MongoDB tools on the market. We guarantee the best compatibility with current and legacy releases of MongoDB, continue to deliver new features with every new software release, and provide high quality support.

Find us on FacebookFind us on TwitterFind us on YouTubeFind us on LinkedIn

Education

  • Free MongoDB Tutorials
  • Connect to MongoDB
  • Connect to MongoDB Atlas
  • Import Data to MongoDB
  • Export MongoDB Data
  • Build Aggregation Queries
  • Query MongoDB with SQL
  • Migrate from SQL to MongoDB

Resources

  • Feedback and Support
  • Sales Support
  • Knowledge Base
  • FAQ
  • Reports
  • Case Studies
  • White Papers
  • Testimonials
  • Discounts

Company

  • About Us
  • Blog
  • Careers
  • Legal
  • Press
  • Privacy Policy
  • EULA

© 2022 3T Software Labs GmbH. All rights reserved.

  • Privacy Policy
  • Cookie settings
  • Impressum
When you click "Accept", you are agreeing to cookies being on your device. They may improve site navigation, site usage analysis, or the relevance of messages. It is up to you which cookies are enabled. Read our Privacy Policy.
Manage cookies
Accept
✕

Privacy Preference Center

A cookie is a small file of letters and numbers that is downloaded on to your computer when you visit a website. Cookies are used by many websites and can do a number of things, eg remembering your preferences, recording what you have put in your shopping basket, and counting the number of people looking at a website. In the form below you can choose which cookies, except for essential cookies, to allow or disable.

Accept all cookies

Manage consent preferences

Essential cookies are strictly necessary to provide an online service such as our website or a service on our website which you have requested. The website or service will not work without them.

Performance cookies allow us to collect information such as number of visits and sources of traffic. This information is used in aggregate form to help us understand how our websites are being used, allowing us to improve both our website’s performance and your experience.

Functional cookies collect information about your preferences and choices and make using the website a lot easier and more relevant. Without these cookies, some of the site functionality may not work as intended.

Social media cookies are cookies used to share user behaviour information with a third-party social media platform. They may consequently effect how social media sites present you with information in the future.

Accept selected