These are chat archives for Automattic/mongoose

6th
Jan 2018
Ivan Nesteruk
@hushino
Jan 06 2018 20:02
Hello.
Screenshot (46320).png
In a nutshell, How do i prevent mongoose.populate() adding a null property, i using ejs template with filters, retrive a Object.values
Ivan Nesteruk
@hushino
Jan 06 2018 20:09
Screenshot (46322).png
.populate({ path: 'episodes', select: 'slug -_id', options: { sort: { createdAt: -1 }, limit: 9 } })
any idea?
<% Object.values(serie.episodes).forEach(function (values) { %> <li><%- link_to(values.slug,'/'+values.slug) %></li> <% }) %>
Ivan Nesteruk
@hushino
Jan 06 2018 21:33
and this is not a mongo error or schema
Kev
@lineus
Jan 06 2018 22:50
hi @hushino I'm not an expert, but since no one else is around I'm happy to ask some questions and try to sort it out with you.
Ivan Nesteruk
@hushino
Jan 06 2018 22:51
hi, @lineus
Kev
@lineus
Jan 06 2018 22:54
what are you calling .populate on? It looks like a document.
Ivan Nesteruk
@hushino
Jan 06 2018 22:59
yes is a document of mongo, I'm using mongoose
Object.values, bring all the values
and the filters to only show the slugs but the rest null
I don't know how to hide them.
Kev
@lineus
Jan 06 2018 23:04
@hushino the document call to populate requires either a callback or .execPopulate but I don't see either in your example. according to the
docs the example shows the document.populate call without a call back or execPopulate as a no-op.
Ivan Nesteruk
@hushino
Jan 06 2018 23:08
i have callback, code works :/
the problem is object.values
Ivan Nesteruk
@hushino
Jan 06 2018 23:16
I don't know how to hide them
if I don't use Object.values the result is in html:
{ slug: 'ramen-daisuki-koizumi-san-1' } { slug: 'fu-ha' } { slug: 'sakurasou-no-pet-na-kanojo' }
Kev
@lineus
Jan 06 2018 23:46
have you tried using the toObject method ? docs here
Ivan Nesteruk
@hushino
Jan 06 2018 23:49
I already tried with toObject and toJSON
Kev
@lineus
Jan 06 2018 23:51
what does Object.getOwnPropertyDescriptors(obj) have to say about the enumerability of the properties?
Ivan Nesteruk
@hushino
Jan 06 2018 23:55
I am going to try