Esteban89
Esteban89

Reputation: 691

collection.find().property returning undefined

I have the following code:

    var permalinkVar = this.params.permalink;
    var imageVar = sites.find({'name':permalinkVar}).createdBy;
    console.log(imageVar);

inside a route function, I'm trying to return the createdBy property, but im not sure why but it's returning undefined. Can anyone help?

Upvotes: 1

Views: 179

Answers (1)

Ethaan
Ethaan

Reputation: 11376

Thas because you are using .find() instead of findOne

var imageVar = sites.findOne({'name':permalinkVar});
console.log(imageVar.createdBy);

.find() returns the collection instance, where .createdBy and name doesn't exists.

Upvotes: 1

Related Questions