Is there anyone know how to use rawCollection and rawConnection?

Can anyone know how to use the new functions of rawCollection and rawConnection that are newly released in 1.0.4 version of Meteor? I have searched from both official docs and even Google, but there is no dos or examples exist yet…

Appreciate any guys could help on this.

1 Like

I am building a system to present a large mount of data in real-time with complex filter form enabled. Now I need provide distinct values from some columns of the data source for drop down list in the filter form. What i am doing now is query data from Mongo DB like:

var opts = myCollection.find(
                    sort: {"Country": 1}
                    fields: {"Country": 1}

then remove duplicates by

_.uniq( (rec) {
                 return rec["Country"];
             }), false);

But I have a few columns that too many uniq values, so the computing pressure is really high.

Just noticed the newest release of Meteor now support the Mongo raw query. So I am thinking if I could use the raw mongo distinct() in meteor now?

Try doing myCollection.rawCollection().find(…).

Thanks. It does not work.
I guess it may be like “myCollection.rawCollection()”.
But I do not know what the format of mongo query to be parsed into…

It seems there is a raw param need be set to true?
I tried these commands on meteor shell, but always made the meteor server crashed…

That’s weird. According to this commit it is supposed to work.

Have tried other kinds of queries like find()?

When using rawCollection you will need to wrap the calls in a ‘meteor fiber’.
Here is part of a method I use to pass an array of documents to insert.
Most of the heavy lifting is done by Meteor.wrapAsync. You are not using mini mongo and must make the node\async code play nice with Meteor. I’ve simplified the code a bit here. You probably want to wrap the call in a try/catch to pick up an error. See the wrapAsync docs.

setWeeklyResults: function(theData) {
// blow away the old documents
            week: theData[0].week
        var collect = WeeklyResults.rawCollection();

        var mongoInsertSync = Meteor.wrapAsync(collect.insert, collect);
        var result = mongoInsertSync(theData);

It does not work as well.

It works now. Thank you, Paul.

1 Like