Is there anyone know how to use rawCollection and rawConnection?


#1

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.


#2

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(opts.map(function (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?


#3

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


#4

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…


#5

That’s weird. According to this commit https://github.com/meteor/meteor/commit/63a0076305b0f204d8acbd322bebd4ded9f2596d it is supposed to work.


#6

Have tried other kinds of queries like find()?


Update multiple array values
#7

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
        WeeklyResults.remove({
            week: theData[0].week
        });
        var collect = WeeklyResults.rawCollection();

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

Kindly help me in Distinct Query
#8

It does not work as well.


#9

It works now. Thank you, Paul.