0

I want to make a query with multiple conditions but the like query is not working:

 exports.getAllPeoduct = async (req, res) => {
        var where = [];

        if(Common.required(req.query.shopId)) where.push({shopId : req.query.shopId});
        if(Common.required(req.query.categoryId)) where.push({categoryId : req.query.categoryId});
        if(Common.required(req.query.price)) where.push({price : req.query.price});
        if(Common.required(req.query.color)) where.push({availableColors :'/.*'+req.query.color+'.*/'});

        console.log(where);

        // if(Common.required(req.query.size)) where.availableSizes = req.query.size;

        try{
            // if(Common.required(shopId)) {

                let getAllProduct = await product.find({$or : where});

                if(getAllProduct.length){
                    Common.sendResponseBack(res, 200,message.OK ,message.getAllProductMessage, getAllProduct);
                } else {
                    Common.sendResponseBack(res, 200, message.OK, message.NoRecordFoundMessage, getAllProduct);
                }
            // } else {
            //  Common.sendResponseBack(res, 403,message.FAIL, message.passAllReqFields, null);
            // }
        } catch (err){
            logger.error( 'Error occured on '+new Date()+' with reason' + err);
            Common.sendResponseBack(res, 403, message.FAIL, message.internalErrorMsg, null);
        }

    }
2
  • What error do you get? Commented Aug 17, 2019 at 12:27
  • i did not get any error in console Commented Aug 17, 2019 at 12:30

1 Answer 1

1

Try something like this:

availableColors : new Regex('/.*'+req.query.color+'.*/')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.