Can you show:

- the retrieved document
- the jade ouput (relevant HTML from your browser source)

Can you add something "definitive" to Jade, template, like p= new Date() (I
don't know if it is a valid Jade syntax). That is, a javascript expression
returning the current date/time, not in the model, but in the view

In this way, you will be more info about the result. It's not clear (in my
English understanding) if you have "cached" result (the same result that
one hour or one minute, or one second ago), or "mangled" (the result is not
what you expected but make senses, or the result is garbage, not expected,
non sense).

Angel "Java" Lopez
@ajlopez







On Wed, Jan 29, 2014 at 7:39 AM, Anto <[email protected]> wrote:

> Hello
>
> It has failed again despite all this, the variables have the right data
> but once fault does not display properly. It's like jade take the cached
> data from another object ( -> products: mongoProducts). Thanks
>
> Regards
> Anto
>
>
> 2014/1/29 Anto <[email protected]>
>
>> Hello
>>
>> It is possible that even use var to define the variable, may exist a bug
>> and take it as a global and have several requests resulting into failure?
>>
>> I've also changed this part of the code being as follows:
>>
>>
>> app.get('/brand/:identifier', function(req, res){
>>
>>     //var identifier = req.params.identifier.toLowerCase();
>>     var term = req.params.identifier.toLowerCase();
>>
>>     brands.find({ active: true, 'brandName' : { $regex : new RegExp(term,
>> "i")} }).populate({
>>
>>                           path: 'shop'
>>
>>                           ,select: 'name shop description'
>>
>>                       }).sort({dateAdded: 'desc'}).exec(function(err,
>> mongoProducts) {
>>         if(mongoProducts && mongoProducts.length) {
>>
>>             console.log('Data doc: ' + mongoProducts);
>>
>>             return res.render('brand_list', {
>>                                                 shop:
>> mongoProducts[0].shop.shop
>>                                                 ,name: mongoProducts[0].
>> shop.name
>>                                                 ,description:
>> mongoProducts[0].shop.description
>>                                                 ,products: mongoProducts
>>                                                 ,pageTitle:
>> mongoProducts[0].shop.shop
>>                                                 ,pageUrl: '
>> http://backofficeserver.local/brand/' + term
>>                             });
>>
>>         } else {
>>
>>             return res.render('brand_list', {
>>                                                 shop:
>> mongoProducts[0].shop.shop
>>                                                 ,name: mongoProducts[0].
>> shop.name
>>                                                 ,description:
>> mongoProducts[0].shop.description
>>                                                 ,error: 'Not product´s
>> found'
>>                                                 ,pageTitle:
>> mongoProducts[0].shop.shop
>>                                 ,pageUrl: '
>> http://backofficeserver.local/brand/' + term
>>                                                  });
>>
>>         }
>>     });
>>
>> });
>>
>> - Jade (resumed)
>>
>> if error
>>    h4= error
>> else
>>   h4= 'List of products'
>>   if products
>>     each product in products
>>       li.product(id=product.identifier, name=product.identifier)
>>         a(href='/show/' + product.identifier, target='_blank')
>>
>> I'll see if it works and the result I will comment. Thanks
>>
>> Regards
>> Anto
>>
>>
>> 2014/1/29 Anto <[email protected]>
>>
>>> hello Ryan
>>>
>>> If I use var to declare variables, was in the transcript of this message
>>> I delete it by mistake, by eliminating several console.log for you they had
>>> the cleanest code. I´m sorry.
>>>
>>> Thanks !
>>>
>>> Regards
>>> Anto
>>>
>>>
>>> 2014/1/29 Ryan Schmidt <[email protected]>
>>>
>>>>
>>>> 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 a topic in the
>>>> Google Groups "nodejs" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/nodejs/2SxmvchhHaM/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>
>>
>  --
> --
> 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.
>

-- 
-- 
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