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 ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I think it’s “safe” based on the fact:
To test if index works properly, you can execute
When seeing
"cursor" : "BtreeCursor s_1", it means the index worked.However, do you consider to modify your application logic and remove
sfield 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.s.