简体   繁体   中英

Mod query in MongoDriver

I try to get the result from mongoDB based on MOD. I prepared Query like below:

{ "customerInfo.Number" : { "$mod" : [ 10 , 1]}}

This query not returning any records from MongoDB. Please let me know anything I am doing wrong.

JSON Structure:

{
  "customerInfo" : {
        "Number" : "89786864361", 
        "ACode" : "8465283639", 
        "BCode" : "1", 
        "CCode" : "638368262782"
    }
}

The reasons why you are not getting the results are

  1. the value of Number is string "89786864362" , change it to a number.
  2. 89786864362%10 == 2 , and you are doing "$mod" : [ 10 , 1] . If you change to "$mod" : [ 10 , 2] you will get the result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM