2015-03-31 42 views
1

如何創建not contains查詢,如果該項目不包含特定值,則返回true。如果它是相關的,我正在運行mongoDB。SailsJS Waterline中的「不包含」查詢

我可以成功使用contains但是當我引入not時會收到錯誤。我用findwhere試過了,但兩次都得到相同的正則表達式錯誤。如果其相關,我可以添加確切的錯誤。

工作版本:

model.find({attribute: {'contains': value}}) 
    .exec(function(err, users) { 
    // happy code 
}); 

下面抱怨一些正則表達式的錯誤:

model.find({attribute: {not: {'contains': value}}}) 
    .exec(function(err, users) { 
    // sad code 
}); 

存在這樣的問題,並提出了在2013年關閉這個問題。也許最近有什麼變化? https://github.com/balderdashy/waterline/issues/22

+0

您是否嘗試過不引用? {not:{contains:value}} – jaumard 2015-03-31 07:05:55

+0

老實說,我試過給'not'添加引號,並嘗試了'Not',但是我從來沒有想過修改'contains',因爲它自己工作。我會在早上 – 2015-03-31 07:07:42

回答

1

到目前爲止,你只能使用Mongodb的本地特性,我認爲。

Model.native(function(err, collection) { 
    collection.find({ 
     "attribute" : { 
      $ne : value, //Not Equal 
      //OR 
      $nin : [value1, value2]// Not In 
     } 
    }).toArray(function(err, docs) { 
     if (err) return callback(err, docs); 

     res.json(null, docs); 
    }); 
}); 
+0

幾天後會試用 – 2015-04-05 16:11:00