Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js collection.find().属性返回未定义_Node.js_Mongodb_Meteor - Fatal编程技术网

Node.js collection.find().属性返回未定义

Node.js collection.find().属性返回未定义,node.js,mongodb,meteor,Node.js,Mongodb,Meteor,我有以下代码: var permalinkVar = this.params.permalink; var imageVar = sites.find({'name':permalinkVar}).createdBy; console.log(imageVar); 在route函数中,我试图返回createdBy属性,但我不确定为什么,但它返回的是未定义的。有人能帮忙吗?因为您使用的是.find()而不是findOne var imageVar = sites.find

我有以下代码:

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

在route函数中,我试图返回
createdBy
属性,但我不确定为什么,但它返回的是未定义的。有人能帮忙吗?

因为您使用的是
.find()
而不是
findOne

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

.find()
返回集合实例,其中
.createdBy
name
不存在。

将返回:
未捕获类型错误:无法读取未定义的属性“createdBy”
仍然在控制台上获得相同的属性:(在站点上键入?应该是站点?如果打印
控制台.log(permalinkVar),会得到什么?
console.log(imageVar)
this.params.permalink
返回什么?尝试
console.log(sites.findOne({name:this.params.permalink})
console.log(permalinkVar)返回正确的“juego”
console.log(imageVar)
返回未定义的
console.log(sites.findOne)({'name':this.params.permalink});
返回unfinedso,
console.log(Sites.findOne({name:this.params.permalink})
应该返回and object,您是否有
waitOn函数
加载模板
?这可能是因为在查找时集合尚未准备好。