简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM