How can i change null values in aggregation using MongoDB -


i'm having hard time code working . have aggregation query in mongo db in witch operations inside . query without $ifnull operator working fine , im getting null values not want printing. i've read documentation of $ifnull operators , not able code working. have code far , witch giving me error :

syntaxerror: unexpected token : 

i think that's ":" ifnull dont know why. i'm following sintax on documentation in official website. 've tried use project field in order filter null values , didnt work. de query far :

 db.cleandrivers.aggregate(  [  {     $project :       { _id:"$_id",          week : {$week : "$recruiter.date"},         dif: {                    $ifnull: [$divide : [{$subtract : ["$personal.stat.first_inspected","$recruiter.date"]}  , 1000 * 60 * 60 ], "0"]              }       }  }, { $match : { week: 11  }  }   ]) 

edit : working fine , query working counting recruited ppl giving specific week.

  db.cleandrivers.aggregate(     ...  [     ...  {     ...  $project :     ...    { _id:"$_id",      ...      week : {$week : "$personal.stat.recruited"}     ...    }     ...  },     ...  { $match : { $and: [ {week: 10}]  }  },      ... {$group: { _id: "sum",sum: {$sum : 1}}} ]) 

output :

   { "_id" : "sum", "sum" : 199 } 

this document sintax :

 "personal" : {                     "stat" : {                             "recruited" : isodate("2015-02-02t14:30:32.089z"),                             "first_inspected" : isodate("2015-02-02t14:33:15.956z"),                             "targo" : isodate("2015-02-06t17:51:00.672z")                     } 

the problem when use same query used when trying count recruited ppl , giving me error ,because there documents not have field. confused on how have filter documents have field first_inspected in documments , , count them givin week . error happens on $week line witch tries convert null date week , gives me error.

i reformatted , patched syntax error:

db.cleandrivers.aggregate([     { "$project" : {         "_id" : "$_id",          "week" : { "$week" : "$recruiter.date" },         "dif" : {                "$ifnull" : [{ "$divide" : [{ "$subtract" : ["$personal.stat.first_inspected", "$recruiter.date"] }, 1000 * 60 * 60 ] }, "0"]         }     } },     { "$match" : { "week" : 11 } }  ]) 

the problem didn't have $divide expression inside object, like

[ "$divide" : stuff, more, stuff] 

instead of

[{ "$divide" : stuff }, more, stuff] 

i can't getting aggregation return want don't know you're looking for. if need more that, edit question include sample document , description of result want it?


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -