天天看點

[Mongo] 解決mongoose不支援條件操作符 $gt$gte:$lte$ne $in $all $not

找到mongoose的安裝目錄

/usr/local/lib/node/mongoose/lib/mongoose/schema

下的檔案:string.js

修改SchemaString.prototype.$conditionalHandlers = {

   '$lt':handleSingle,

    '$lte':

handleSingle,

    '$gt':

    '$gte':

'$all':handleArray,

    '$ne':

    '$in':

handleArray,

    '$nin':

handleArray

};

模糊查詢:

在mongodb中:

db.admins.find({loginName:{$all:[/^a.*/]}});

在mongoose中

var q = new RegExp("^" + key +".*");//所有以傳入參數開始的

userM.admins.find({loginName:{'$all':[q]}},function(err,

results){      

    if (err)

{

console.log(err);

}

else {

res.send(results);

});   

$findCondition = array(

繼續閱讀