I use Mongoose on my website right now and I currently have 2 databases. The first holds a list of all possible items and looks like this:
{ _id:2
name:"Cat Food"
imgUrl:"/images/basicFood.png"
description:"Basic food that will fill your pets up nice and full."
__v:0
cost:"5"}
{ _id:3
name:"Premium Cat Food"
imgUrl:"/images/premiumFood.png"
description:"This food has a 5% chance of raising a stat on your pet!"
cost:"10"}
etc..
The second holds each individual user's inventory and looks like this:
{ 2:12
3:7
_id:3
userId:3}
Where in this instance the user owns 12 of item #2 and 7 of item# 3. The key is the item number and the value is how many they own.
I am passing the inventory entry for the individual user to their Inventory page. I want to then display the inventory like so:
[#2 image] [#3 image]
Owned: 12 Owned: 7
So I need the inventory.ejs page to access the first database, reference the image url associated with the item number, and display that followed by how many of each item is owned. So far I have gotten the inventory for the individual user passed to the EJS page as an object. When logged from the EJS file, the correct information prints out as
{ '2': 12, '3': 7, _id: 3, userId: 3 }
However I cannot get the proper information to display on the page. Here is what I am using right now:
<%= invenList %>
<% for(const key in invenList) {%>
<% if (invenList.hasOwnProperty(key)) {%>
<% console.log(key);%>
<% }%>
<% }%>
But this is printing out entirely the wrong set of keys. It gives me
$__
isNew
errors
$locals
$op
_doc
$init
instead of the expected
2
3
_id
userId
I need help figuring out how to get the right information from the for/in loop as well as how to connect to this other database and use the key to grab the image url for each item. Please make explanations as detailed as possible as I'm a beginner.