Direct mongo commands

944 views
Skip to first unread message

Vasiliy Arnautov

unread,
Jan 12, 2014, 3:54:35 AM1/12/14
to meteo...@googlegroups.com
Hello!

How to use direct mongo commands such as aggregate method for mongo collections? TY

Richard Fielding

unread,
Jan 13, 2014, 8:44:07 PM1/13/14
to meteo...@googlegroups.com
If you only want to do it on the server, you can access the raw mongo collection via a cursor, and then do the aggregation with the raw collection :

// collection is meteor collection
var collectionMongo = collection.find()._mongo.db.collection(collection._name);
collectionMongo['aggregate'](pipeline, cb)

haven't got very far implementing this but it worked basically on the server. On the client it might be more complicated since you have minimongo

Bit of a hack though, would be interested to see other ways of doing it...

gerard sychay

unread,
Jan 14, 2014, 11:22:19 AM1/14/14
to meteo...@googlegroups.com
There are a few mongo aggregation meteor packages. I've used this one before:


And this one appears to enhance that one a bit: 


HTH,
Gerard

Vasiliy Arnautov

unread,
Jan 15, 2014, 10:02:10 AM1/15/14
to meteo...@googlegroups.com
I can't use these, because I used SmartCollections instead of regular meteor Collections.

вторник, 14 января 2014 г., 20:22:19 UTC+4 пользователь gerard sychay написал:

Vasiliy Arnautov

unread,
Jan 15, 2014, 4:36:04 PM1/15/14
to meteo...@googlegroups.com
This is similar as https://github.com/meteor/meteor/pull/644 This works only with Meteor Collections.I can't use Smart Collections and ordinary collections simultaneously =\


вторник, 14 января 2014 г., 5:44:07 UTC+4 пользователь Richard Fielding написал:

Vasiliy Arnautov

unread,
Jan 15, 2014, 5:07:15 PM1/15/14
to meteo...@googlegroups.com
Let me explain this.
I do 
var Userdata = new Meteor.SmartCollection("userdata");

i cant create
var collection = new Meteor.Collection("userdata");
because i getting Error: A method named '/userdata/insert' is already defined



четверг, 16 января 2014 г., 1:36:04 UTC+4 пользователь Vasiliy Arnautov написал:

Steve Dossick

unread,
Jan 15, 2014, 5:26:47 PM1/15/14
to meteo...@googlegroups.com
We've been a little bit wary of using atmosphere/meteorite packages in our app before Meteor gets it package story totally nailed down.

For the one place on the server where we needed aggregation (and ensureIndex calls), we use a new instance of MongoInternals.RemoteCollectionDriver.  Yes, we know this _will_ break at some point.

Something like this:

ServerUtils = {};

Meteor.startup(function() {
    ServerUtils.mongoConnection = new MongoInternals.RemoteCollectionDriver(Config.mongoUrl);
});

-s



--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Richard Fielding

unread,
Jan 15, 2014, 6:44:12 PM1/15/14
to meteo...@googlegroups.com
If you only need aggregation on the server, you really only need to access the mongo collection...

In the SmartCollections code I see this

  function createCollection() {
    self._collection = Meteor.SmartMongo.connection.db.collection(collectionName);
    self.emit('ready');
    self._debug('ready');
  }

so you can probably just do mySmartCollection._collection and you'll have the raw mongo collection ready.

and so 

mySmartCollection._collection['aggregate'](pipeline, myCallback); 

might well work

Vasiliy Arnautov

unread,
Jan 16, 2014, 5:23:41 PM1/16/14
to meteo...@googlegroups.com
MANY THANKS! Problem was solved.

четверг, 16 января 2014 г., 3:44:12 UTC+4 пользователь Richard Fielding написал:
Reply all
Reply to author
Forward
0 new messages