how to get all data with special condition on mongodb -


how data condition discountprice not nil?

if have object inside mongo db :

when i'm execute query "db.products.find()", result below :

{     "_id" : objectid("123456778"),     "items" : [         {             "discountprice" : 159200,             "_id" : objectid("54697e689857572459444162"),         }     ] }, {     "_id" : objectid("847446468"),     "items" : [         {             "discountprice" : nil,             "_id" : objectid("54697e689857572459444162"),         }     ] } 

how result :

{         "_id" : objectid("123456778"),         "items" : [             {                 "discountprice" : 159200,                 "_id" : objectid("54697e689857572459444162"),             }         ]     } 

how that?

you can use $ne operator match values "not equal" null:

db.products.find( { "items.discountprice": { "$ne": null } } ) 

i've changed reference of nil null because nil not valid bson type. i'm assuming using ruby uses nil in favor of null. using mongodb drivers, think you'll still able supply value nil, in language agnostic post correct value null.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -