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 8999293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:09:40+00:00 2026-06-16T00:09:40+00:00

I have a index {s:1} on collection k like: Data in k likes :

  • 0

I have a index {s:1} on collection k like:

Data in k likes :


{ s:"aaa"} ,
{s:"bbb"} ,
{s:""}

Is it safe to use {s:{$gt:""}} to find out every item that the length of s greater than 0 ?

  • 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-16T00:09:41+00:00Added an answer on June 16, 2026 at 12:09 am

    I think it’s “safe” based on the fact:

    • Any non-empty string is greater than empty string in lexicographical order.
    • The index works properly so performance should be ok.

    To test if index works properly, you can execute

    db.collectionName.find({s: {$gt: ""}}).explain()
    

    When seeing "cursor" : "BtreeCursor s_1", it means the index worked.

    However, do you consider to modify your application logic and remove s field when it’s empty?

    • db.test.find({s: {$exists: false}}).hint({s: 1}) can be used in this query. It is more nature than $gt.
    • You can benefit from MongoDB sparse index in performance. Especially when most of your data are with empty s.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have data in my users collection that looks like: { name: '...',
I have a collection, the data look like this: { _id : ObjectId(4e627655677c27cf24000000), gps
I have a collection with a relatively big index (but less than ram available)
I have in my app/views/bar/index.html.haml the following %p= render partial: 'foo', collection: @foos the
I have a index.php page that is the main page. All pages are included
Could someone please help me find out why my attempt to bind Collection to
I have a html select syntax like : <select id=salary_structure_salary_structure_line_items_attributes_0_payhead_id class=half name=salary_structure[salary_structure_line_items_attributes][0][payhead_id]> <option data-payhead=Earnings
I have a mid-size collection of records --about 20 million -- that I need
I want to create a collection of classes that behave like math vectors, so
I have a document in RavenDB that looks looks like: { ItemId: 1, Title:

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.