Underscores for Readability with Number Types

Hi, folks.

I’m new to MongoDB, and had a question about using the .find() method with a query.

If a value is stored within a document field as an integer, and that integer is large enough that it becomes hard to read; am I able to query for it with an integer that has underscore separators even if the value itself within document field doesn’t have underscore separators?

Example Document:

   <field>: 1000000

Example Query:

db.<collection>.find({<field>: 1_000_000}); 
1 Like

If you are using mongodb inside Node (like Mongo Shell), or anything that will be interpreted as JS, the answer is yes.

If you query from the browser, should check the support in caniuse.com though. Also this is a nice little post about it. Numeric Separators in JavaScript - DEV Community 👩‍💻👨‍💻

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.