Mongoose optional search query parameters?

前端 未结 3 1900
时光说笑
时光说笑 2020-11-28 15:56

I have a following situation. I need to build a mongoose query, based on certain arguments if present.

I.e. if object like this is passed

{
    playe         


        
3条回答
  •  孤独总比滥情好
    2020-11-28 16:34

    Build up your query object programmatically:

    var query = {
        player: 'player'
    };
    
    if (obj.action) {
        query.action = obj.action;
    }
    
    Entry.find(query).exec(function(err, res){
        console.log(res);
    });
    

提交回复
热议问题