On Jan 28, 2014, at 19:39, Anto <[email protected]> wrote:

> The code is as follows:
> 
> - Nodejs + Expressjs
>                                                    
> app.get('/brand/:identifier', function(req, res){
> 
>     identifier = req.params.identifier.toLowerCase();    

Because you have not used "var" to declare it, "identifier" is a global 
variable. This is a problem. Check your other code for this problem as well.

>     brands.find({ active: true, 'brandName' : { $regex : new 
> RegExp(identifier, "i")} }).populate({
>                                                                               
>                       path: 'shop'
>                                                                               
>                       ,select: 'name shop description'
>                                                                               
>                   }).sort({dateAdded: 'desc'}).exec(function(err, doc) {

Here, you are firing off an asynchronous function (brands.find); when it is 
done, the anonymous function (function(err, doc){...}) will be called with the 
result.

>         if(doc && doc.length) {
>             
>             console.log('Data doc: ' + doc);
>             
>             return res.render('brand_list', {
>                                                 shop: doc[0].shop.shop
>                                                 ,name: doc[0].shop.name
>                                                 ,description: 
> doc[0].shop.description
>                                                 ,products: doc 
>                                                 ,pageTitle: doc[0].shop.shop
>                                                 ,pageUrl: 
> 'http://backofficeserver.local/brand/' + identifier
>                                                           });
>                 
>         } else {
>         
>             return res.render('listado_shop', {
>                                                 shop: doc[0].shop.shop
>                                                 ,name: doc[0].shop.name
>                                                 ,description: 
> doc[0].shop.description
>                                                 ,error: 'Not product´s found'
>                                                 ,pageTitle: doc[0].shop.shop
>                                                               ,pageUrl: 
> 'http://backofficeserver.local/brand/' + identifier
>                                                 });
>     
>         }

Here you are rendering the jade template, using various values, including that 
global variable "identifier". But between the time that this request started, 
and the time that the database returned the result and the template was 
rendered, another request may have started and overwritten the "identifier" 
variable with a different value.

Use "var" to declare your local variables so that they stay local and don't 
pollute other requests.


-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to