Mongodb 在meteor中处理FS.collection
我想从订阅我的images fs.collection中筛选结果 集合声明如下:Mongodb 在meteor中处理FS.collection,mongodb,meteor,fs,Mongodb,Meteor,Fs,我想从订阅我的images fs.collection中筛选结果 集合声明如下: Images = new FS.Collection('images', { stores: [ImagesStore], filter: { //maxSize: 1048576 * 1, //in bytes //1MB maxSize: 512 * 1024, //in bytes allow: { contentTypes: ['image/*'],
Images = new FS.Collection('images', {
stores: [ImagesStore],
filter: {
//maxSize: 1048576 * 1, //in bytes //1MB
maxSize: 512 * 1024, //in bytes
allow: {
contentTypes: ['image/*'],
extensions: ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF' ]
},
onInvalid: function (message) {
if (Meteor.isClient) {
alert("Your file must be a ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF' ], and must not exceed 512KBytes");
sAlert.error(message, {effect: 'stackslide', position: 'left-top', timeout: '3000'});
} else {
console.log(message);
}
}
}
});
FS.HTTP.setBaseUrl('/usrImg');
Images.deny({
insert: function(userId, fileObj) {
return false;
},
update: function(userId, fileObj) {
return false;
},
remove: function(userId, fileObj) {
return false;
},
download: function(userId, fileObj /*, shareId*/) {
return false;
},
fetch: []
});
Images.allow({
insert: function(userId, fileObj) {
return true;
},
update: function(userId, fileObj) {
return true;
},
remove: function(userId, fileObj) {
return true;
},
download: function(userId, fileObj /*, shareId*/) {
return true;
},
fetch: [] // ['owner']
});
var i = -1,
array = [],
usrAvatarId = Meteor.users.find({"profile.avatar.type": "doc"}, {fields: {"profile.avatar.data": 1}}).fetch(),
nbAvatar = Meteor.users.find({"profile.avatar.type": "doc"}).count();
console.log(nbAvatar);
console.log(usrAvatarId);
while(++i < nbAvatar)
array.push(usrAvatarId[i]._id);
console.log(array);
Meteor.subscribe('images', array);
订阅内容如下:
Images = new FS.Collection('images', {
stores: [ImagesStore],
filter: {
//maxSize: 1048576 * 1, //in bytes //1MB
maxSize: 512 * 1024, //in bytes
allow: {
contentTypes: ['image/*'],
extensions: ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF' ]
},
onInvalid: function (message) {
if (Meteor.isClient) {
alert("Your file must be a ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF' ], and must not exceed 512KBytes");
sAlert.error(message, {effect: 'stackslide', position: 'left-top', timeout: '3000'});
} else {
console.log(message);
}
}
}
});
FS.HTTP.setBaseUrl('/usrImg');
Images.deny({
insert: function(userId, fileObj) {
return false;
},
update: function(userId, fileObj) {
return false;
},
remove: function(userId, fileObj) {
return false;
},
download: function(userId, fileObj /*, shareId*/) {
return false;
},
fetch: []
});
Images.allow({
insert: function(userId, fileObj) {
return true;
},
update: function(userId, fileObj) {
return true;
},
remove: function(userId, fileObj) {
return true;
},
download: function(userId, fileObj /*, shareId*/) {
return true;
},
fetch: [] // ['owner']
});
var i = -1,
array = [],
usrAvatarId = Meteor.users.find({"profile.avatar.type": "doc"}, {fields: {"profile.avatar.data": 1}}).fetch(),
nbAvatar = Meteor.users.find({"profile.avatar.type": "doc"}).count();
console.log(nbAvatar);
console.log(usrAvatarId);
while(++i < nbAvatar)
array.push(usrAvatarId[i]._id);
console.log(array);
Meteor.subscribe('images', array);
目前的目标是将包含允许的文件ID的数组作为参数传递
当我记录collection客户端时,我确实拥有一个带有_id属性的文件数组
但当我尝试这个:
Meteor.publish('images', function(array){
console.log(array);
return Images.find({_id: {$in: array}});
});
我没有得到任何文档,认为服务器正确地记录了传递的数组
我可能遗漏了一些东西:我不习惯FS.collection,它的文档也不是我迄今为止见过的最容易理解的
关于允许/拒绝,我不认为它在这里改变了什么,但是我没有从我以前开始的源代码中改变它们
有人能帮忙吗?每次连接下载200个文件越来越无聊:/
谢谢基本上,您正在尝试进行连接,以便只下载与您发布到客户端的用户对应的图像 更好、更简单、更快的方法是使用包获取发布用户所在的同一出版物中的图像 我用自己的应用程序中的FS.collection做了很长时间,效果非常好