2013-05-13 75 views
55

展望做folling查詢:貓鼬查詢,其中值不爲空

Entrant 
    .find 
     enterDate : oneMonthAgo 
     confirmed : true 
    .where('pincode.length > 0') 
    .exec (err,entrants)-> 

我在做的where子句是否正確?我要選擇的文件,其中pincode不爲空

回答

99

你應該能夠做到這一點像(如你正在使用的查詢API):

Entrant.where("pincode").ne(null) 

...這將導致蒙戈查詢內容大致如下:

entrants.find({ pincode: { $ne: null } }) 

幾個環節,這可能有助於:

+1

什麼NE代表什麼? – wesbos 2013-05-13 22:12:35

+2

「不等於」,添加鏈接到答案 – numbers1311407 2013-05-13 22:15:59

+0

關於它的mongodb文檔在這裏(現在): http://docs.mongodb.org/manual/reference/operator/query/ 最新的文檔關於它,在這裏:http://mongoosejs.com/docs/api.html#query_Query-ne – zeropaper 2014-07-20 07:52:10

2

我在這裏結束了,我的問題是,我查詢的

{$not: {email: /@domain.com/}} 

代替

{email: {$not: /@domain.com/}} 
+0

只是說明這正是我正在尋找我自己,謝謝! – Cacoon 2018-01-30 10:03:05