Mongoose - Unable to fetch data in find

Question

I am sending an api request which contains space. I remove the space with decodeURIComponent but still I am getting [] in response. Here is my code

    router.get('/products/searchproduct/:name', (req, res, next) => {

    var request = decodeURIComponent(req.params.name)
    console.log('------------------------------------');
    console.log(request);
    console.log('------------------------------------');
    Product.find({
        'category.category_name': decodeURIComponent(req.params.name)
    }, function (err, document) {
        if (err)
            return res.status(500).send("There was a problem getting the category based record .");
        console.log('------------------------------------');
        console.log(decodeURIComponent(req.params.name));
        console.log('------------------------------------');
        res.status(200).send(document);

    })
});

enter image description here

product schema

    //this file contain content scheme

const mongoose = require('mongoose');

//function to call monggose schema
const ProductSchema = mongoose.Schema({
    product_name: {
        type: String,
        required: true
    },
    product_rating: {
        type: Number,
        required: true
    },
    product_price: {
        type: String,
        required: true
    },
    product_btc: {
        type: String,
        required: true
    },
    product_mode: {
        type: String,
        required: true
    },
    product_date: {
        type: String,
        required: true
    },
    product_hasrate: {
        type: String,
        required: true
    },
    product_powerConsumption: {
        type: String,
        required: true
    },
    product_efficiency: {
        type: String,
        required: true
    },
    product_voltage: {
        type: String,
        required: true
    },
    product_frequency: {
        type: String,
        required: true
    },
    product_shipment: {
        type: String,
        required: true
    },
    product_warranty: {
        type: String,
        required: true
    },
    product_contact: {
        type: String,
        required: true
    },
    category: [mongoose.Schema.Types.Mixed]
})

const Product = module.exports = mongoose.model('Product', ProductSchema);

Show source
| find   | node.js   | mongoose   | api   | mongodb   2017-10-24 13:10 0 Answers

Answers to Mongoose - Unable to fetch data in find ( 0 )

Leave a reply to - Mongoose - Unable to fetch data in find

◀ Go back