I wanted to get random files , but skip does not seem very effecient, So tried to install meteorhacks:aggregate, it seems to be working fine for Mongo.Collection, but not for FileCollection, when I tried to use .aggregate function on the file collection, it gives me
Uncaught TypeError: Images.aggregate is not a function error
Can Meteor-Files support aggregation operation? Mongodb is supporting it from version 3, Thanks.
Use Images.collection, read more about direct collection usage here
Tried that, calling Images.collection.aggregate() give error
Uncaught TypeError: Images.collection.aggregate is not a function
Below is the code for the method
Meteor.methods({
getRandomSelfies:function(size){
return Images.collection.aggregate({$sample:{size:size}})
}
})
Make sure you're on Server as meteorhacks:aggregate is server only package
The mothod above should be server side I believe
On client side I'm using Meteor.call('getRandomSelfies',2500) for calling that method
Images.find() method works fine and returns all records, I used skip() for achieving same effect, but think aggregate is more effecient.
Right, what on server-side you're getting from?:
console.log(Images.collection);
console.log(Images.collection.aggregate)
Have you tried to call .aggregate() on other default Mongo.Collection?
Like Meteor.users.aggregate()? To make sure meteorhacks:aggregate is working?
Okay, let me try
Ah my bad, it was not working for other Collections now, somehow I broke something, meteorhacks:aggregate not working correctly. I'll post how I did after I was able to use aggregate with FileCollection.
Thanks you very much :)
On server side calling Images.collection.aggregate({$sample:{size:1000}}); worked perfectly! Confirmed, meteorhacks:aggregate works nicely with Meteor-Files collection.
Can close this now.
Hi @bevinhex I'm glad it's solved. The one thing I was afraid of meteorhacks:aggregate - it's stale project with last commit more than 2 years ago. Thank you for testing this out.
Please, support this project by: