sql >> Base de Datos >  >> NoSQL >> MongoDB

Cómo iterar a través de un objeto dentro de la colección Meteor Mongo

Esta es una pregunta de JavaScript, no necesariamente Meteor. Usa un for-in bucle para iterar a través de objetos.

// This query returns an object
var MyObject = VideoCourses.find({'_id': 'jkwehrjewrew'}).fetch()[0].videos

// The object is brings back looks like this:
// {    
//  first: "firstvideo.html", 
//  second: "secondvideo.html", 
//  third: "thirdvideo.html"
// };


// Use a for-in loop to iterate through the object
for(key in myObject){
    console.log("this is the key: ", key, ", and this is the value: ", myObject[key]);
};