Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8090831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:51:13+00:00 2026-06-05T19:51:13+00:00

How can I have a mongo query similar to the SQL …WHERE _id >

  • 0

How can I have a mongo query similar to the SQL “…WHERE _id > threshold”

I tried the following, but it doesn’t give me any result.

 db.things.find(_id: {$gt: someid} });

Is it because the _id field is a little special, in that it has the format?

_id : {"$oid" : "someid"} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:51:15+00:00Added an answer on June 5, 2026 at 7:51 pm

    Compare like with like

    The _id key in mongo is not (by default) a string – it is a mongo objectId.

    You need to compare to the same type to get a meaningful result:

    var ObjectId = require('mongodb').ObjectID;
    var oid = new ObjectId();
    db.things.find(_id: {$gt: oid});
    

    Don’t read mongoexport files

    Mongo export files look like this:

    { "_id" : { "$oid" : "4f876b00c56da1fa6a000030" }, ...
    

    This is a json representation of an object id. Mongo doesn’t want you to use that kind of syntax when actually querying the db. This will not work:

    # will not work
    db.things.find("_id.$oid": {$gt: "string"});
    

    id as a string

    If you have the id as a string, you’d do:

    var ObjectId = require('mongodb').ObjectID;
    var str = "123456789012345678901234";
    var oid = new ObjectId(str);
    db.things.find(_id: {$gt: oid});
    

    id as a partial string

    If the string you have is not a valid oid (not 24 chars long), you’ll just get an exception from mongo – or depending on your driver, a new oid. If you have a partial object id you can pad with 0s to make a valid oid and therefore permit finding by partial object ids. e.g.:

    var ObjectId = require('mongodb').ObjectID;
    var oid = new ObjectId(str + "0000");
    db.things.find(_id: {$gt: oid});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following MongoDB object stored in my Mongo database: array ( '_id'
In Mongo my understanding is that you can have databases and collections. I'm working
I have a field 'Description' which can have product descriptions with any unicode characters.
I have a property column which can have a subset of the following values
I'd like to query a mongo collection for records which either don't have a
Can Mongo IDs have the same value in different collections in the same database?
I have a Mongo collection called documents which has the following structure: { name:
I have a query made using linq to SQL which result will be shown
Is there any way in which I can tell mongo to return documents till
Shaders can have lots of different uniform names + attributes. How can I make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.