node.js - MongoDb query for Month comparision in loopback application -


i using mongodb datasource loopback application. in have retrieve documents current month.

so tried following:

app.models.aaaa.count({ $where : 'return this.date.getmonth() == 7'}, function(err, res){ }); 

now want filter based on year , userid also. how can construct query that.

i tried following:

app.models.aaaa.count({ $where : 'return this.date.getmonth() == 7 && this.date.getyear() == 2016'}, function(err, res){     }); 

but checks month..please share ideas. in advance

edit:

[   {     "aaaid": "57a84a572b9a79022198c6dd",     "bbid": "876hjg786",     "date": "2016-08-08t00:00:00.000z",     "cccc": [       "57a1bfd0c77554fd746a538d'",       "57a1bfebc77554fd746a538f"     ],     "id": "57a85e1d9841c9cb1b100f21"   },   {     "aaaid": "57a84a572b9a79022198c6dd",     "bbid": "876hjg786",     "date": "2016-08-08t00:00:00.000z",     "cccc": [       "57a1bfd0c77554fd746a538d'",       "57a1bfebc77554fd746a538f"     ],     "id": "57a85f1d1605d9f11b4d21b3"   } ] 

this should work:

db.mycollection.count(    function() {      return (this.date.getmonth() == 7 && this.date.getyear() == 2016);    } ); 

note if have $where, can write javascript function .count() argument, or expression string follows:

db.mycollection.count("this.date.getmonth() == 7 && this.date.getyear() == 2016"); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -