我想迭代meteor(服务器端)中的多个Mongo集合.首先,我想检查一个集合是否有任何文件.
我的代码到目前为止:
var isEmptyCollection = function(name) {
if(name.find().count() === 0) {
return true
} else {
return false
}
};
var mycollections = ["CollectionOne", "CollectionTwo", "CollectionThree"];
for (var i = 0; i < mycollections.length; i++) {
if (isEmptyCollection(mycollections[i])) {
} else {
var data = mycollections[i].find({},{fieldOne: 1}).fetch();
console.log(data);
}
我收到此错误:
TypeError: Object CollectionOne has no method 'find'....
如果集合有任何值,我如何迭代集合/检查循环?
最佳答案 您的集合数组包含许多字符串,但它应包含集合对象列表.尝试将数组赋值更改为:
var mycollections = [CollectionOne, CollectionTwo, CollectionThree];
我假设你已经使用Mongo.Collection定义了这些.