My monongodb schema looks like this:
let statSchema = new mongoose.Schema({
title: String,
statId: String,
stats: {
likeCount: Number,
commentCount: Number
}
});
let MyStat = mongoose.model("MyStat", statSchema);
I am looking for a way where I can get all the statId
elements from the database and put them in an array.
Later on I want to go through that array with request
(npm request) that will take the statId
and request JSON from API that will update all stats
(likeCount and commentCount) for each corresponding statId
.
If I use this code below:
MyStat.find({}, function(err, foundStats){
if (err) throw err;
console.log(foundStats);
});
it will log all the elements in my database but I don't know how to access just 'statId'.
I was trying to use console.log(foundStats.linkId);
but it returns undefined
.