meabhisingh / mernProjectEcommerce

This is MERN Stack Ecommerce Project Made to Teach MERN Stack on YouTube
1.15k stars 828 forks source link

Search/Filer Optimization Postman Returning False #48

Open HetMamtora opened 1 year ago

HetMamtora commented 1 year ago

image

utils/apifeature.js

class ApiFeatures { constructor(query, queryStr) { this.query = query; this.queryStr = queryStr; } search() { const keyword = this.queryStr.keyword ? { name: { $regex: this.queryStr.keyword, $options: "i", }, } : {};

  this.query = this.query.find({ ...keyword });
  return this;
}

filter(){
  const queryCopy = {...this.queryStr}
  console.log(queryCopy)
  //REMOVE SOME FIELDS
  const removeFields = ["keyword","page","limit"];

  removeFields.forEach(key=>delete queryCopy[key])
  this.query = this.query.find(queryCopy)

}

} module.exports = ApiFeatures;

controllers/productController.js

//GET PRODUCT DETAILS `exports.getProductDetails = catchAsyncErrors(async(req,res,next)=>{

const product = await Product.findById(req.params.id)

if(!product){
    return next(new ErrorHandler("Product Not Found",404))
}

res.status(200).json({
    success:true,
    product
})

})`

Help me over this error. I'm using the same code from GitHub files but postman is returning Success: False with error as Query cannot read properties.

codeomi commented 1 year ago

You are using the wrong controller, use getProduct controller rather than getProductDetails.

HetMamtora commented 1 year ago

You are using the wrong controller, use getProduct controller rather than getProductDetails.

Solved, Thank You for your response.

umar1103 commented 1 year ago

I have the same postman error Success:false Message: cannot read the properties of undefined reading keyword

HetMamtora commented 1 year ago

I have the same postman error Success:false Message: cannot read the properties of undefined reading keyword

Share your code. In which file you are getting error.

umar1103 commented 1 year ago

Now mongodb is not working Can i get your contact number?

On Sat, Apr 15, 2023, 10:57 AM HetMamtora @.***> wrote:

I have the same postman error Success:false Message: cannot read the properties of undefined reading keyword

Share your code. In which file you are getting error.

β€” Reply to this email directly, view it on GitHub https://github.com/meabhisingh/mernProjectEcommerce/issues/48#issuecomment-1509523350, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBNFSU4GR5257GSM64TXBIWVNANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.***>

HetMamtora commented 1 year ago

Sorry brother, can't share my contact no. Change in your config file If you are using localhost link as http://localhost:"portnumber"

Change it to http:// 0.0.0.0:"portnumber"

If this doesn't work i would suggest you to refer docs of express and mongoDb

umar1103 commented 1 year ago

Before some time it was working but now , neither postman is working nor mongodb πŸ₯²

On Sat, Apr 15, 2023, 11:24 AM HetMamtora @.***> wrote:

Sorry brother, can't share my contact no. Change in your config file If you are using localhost link as http://localhost:"portnumber"

Change it to http:// 0.0.0.0:"portnumber"

If this doesn't work i would suggest you to refer docs of express and mongoDb

β€” Reply to this email directly, view it on GitHub https://github.com/meabhisingh/mernProjectEcommerce/issues/48#issuecomment-1509549794, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBOVADMRNSF3BCLF55LXBIZ2TANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.***>

HetMamtora commented 1 year ago

Before some time it was working but now , neither postman is working nor mongodb πŸ₯² … On Sat, Apr 15, 2023, 11:24 AM HetMamtora @.> wrote: Sorry brother, can't share my contact no. Change in your config file If you are using localhost link as http://localhost:"portnumber" Change it to http:// 0.0.0.0:"portnumber" If this doesn't work i would suggest you to refer docs of express and mongoDb β€” Reply to this email directly, view it on GitHub <#48 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBOVADMRNSF3BCLF55LXBIZ2TANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.>

Try the method that I suggested. If it doesn't work.

More I can suggest is begin from scratch for that particular code snippet.

umar1103 commented 1 year ago

It is showing this only

On Sat, Apr 15, 2023, 11:32 AM HetMamtora @.***> wrote:

Before some time it was working but now , neither postman is working nor mongodb πŸ₯² … <#m6613579211547683256> On Sat, Apr 15, 2023, 11:24 AM HetMamtora @.> wrote: Sorry brother, can't share my contact no. Change in your config file If you are using localhost link as http://localhost:"portnumber http://localhost:%22portnumber" Change it to http:// 0.0.0.0 http://0.0.0.0:"portnumber" If this doesn't work i would suggest you to refer docs of express and mongoDb β€” Reply to this email directly, view it on GitHub <#48 (comment) https://github.com/meabhisingh/mernProjectEcommerce/issues/48#issuecomment-1509549794>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBOVADMRNSF3BCLF55LXBIZ2TANCNFSM6AAAAAAVYSLDDU https://github.com/notifications/unsubscribe-auth/ASIKEBOVADMRNSF3BCLF55LXBIZ2TANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.>

Try the method that I suggested. If it doesn't work.

More I can suggest is begin from scratch for that particular code snippet.

β€” Reply to this email directly, view it on GitHub https://github.com/meabhisingh/mernProjectEcommerce/issues/48#issuecomment-1509554673, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBLL32KAKB5GN6E4JVDXBI2YJANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.***>

umar1103 commented 1 year ago

?

On Sat, Apr 15, 2023, 11:42 AM sheikh umar @.***> wrote:

It is showing this only

On Sat, Apr 15, 2023, 11:32 AM HetMamtora @.***> wrote:

Before some time it was working but now , neither postman is working nor mongodb πŸ₯² … <#m_5329040672286795945_m6613579211547683256> On Sat, Apr 15, 2023, 11:24 AM HetMamtora @.> wrote: Sorry brother, can't share my contact no. Change in your config file If you are using localhost link as http://localhost:"portnumber http://localhost:%22portnumber" Change it to http:// 0.0.0.0 http://0.0.0.0:"portnumber" If this doesn't work i would suggest you to refer docs of express and mongoDb β€” Reply to this email directly, view it on GitHub <#48 (comment) https://github.com/meabhisingh/mernProjectEcommerce/issues/48#issuecomment-1509549794>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBOVADMRNSF3BCLF55LXBIZ2TANCNFSM6AAAAAAVYSLDDU https://github.com/notifications/unsubscribe-auth/ASIKEBOVADMRNSF3BCLF55LXBIZ2TANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.>

Try the method that I suggested. If it doesn't work.

More I can suggest is begin from scratch for that particular code snippet.

β€” Reply to this email directly, view it on GitHub https://github.com/meabhisingh/mernProjectEcommerce/issues/48#issuecomment-1509554673, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBLL32KAKB5GN6E4JVDXBI2YJANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.***>

umar1103 commented 1 year ago

Actually I end task of mongodb in task manager from then it is not connecting to mongodb

On Sat, Apr 15, 2023, 11:57 AM sheikh umar @.***> wrote:

?

On Sat, Apr 15, 2023, 11:42 AM sheikh umar @.***> wrote:

It is showing this only

On Sat, Apr 15, 2023, 11:32 AM HetMamtora @.***> wrote:

Before some time it was working but now , neither postman is working nor mongodb πŸ₯² … <#m_-8400313493578459407_m_5329040672286795945_m6613579211547683256> On Sat, Apr 15, 2023, 11:24 AM HetMamtora @.> wrote: Sorry brother, can't share my contact no. Change in your config file If you are using localhost link as http://localhost:"portnumber http://localhost:%22portnumber" Change it to http:// 0.0.0.0 http://0.0.0.0:"portnumber" If this doesn't work i would suggest you to refer docs of express and mongoDb β€” Reply to this email directly, view it on GitHub <#48 (comment) https://github.com/meabhisingh/mernProjectEcommerce/issues/48#issuecomment-1509549794>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBOVADMRNSF3BCLF55LXBIZ2TANCNFSM6AAAAAAVYSLDDU https://github.com/notifications/unsubscribe-auth/ASIKEBOVADMRNSF3BCLF55LXBIZ2TANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.>

Try the method that I suggested. If it doesn't work.

More I can suggest is begin from scratch for that particular code snippet.

β€” Reply to this email directly, view it on GitHub https://github.com/meabhisingh/mernProjectEcommerce/issues/48#issuecomment-1509554673, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASIKEBLL32KAKB5GN6E4JVDXBI2YJANCNFSM6AAAAAAVYSLDDU . You are receiving this because you commented.Message ID: @.***>