user3475602
user3475602

Reputation: 1217

Access native mongoDB collection in Meteor

I am using this ShareJS package in my Meteor application. ShareJS uses the collections docs and ops. How can I access these collections from the server? Do I have to define them as collections as well?

Upvotes: 0

Views: 175

Answers (1)

Seth Malaki
Seth Malaki

Reputation: 4486

You can use MongoInternals. But make sure to wrap it in a Future for it to behave correctly. I like the following IIFE pattern the most:

var connection = MongoInternals.defaultRemoteCollectionDriver().mongo;

var searchResults = (function(collectionName, query) {

    var future = new Future(); 

    connection._getCollection(collectionName)
      .find(query)
      .toArray(function(error, results) {
        if(error) future.throw(error);
        else future.return(results || []);
      });      

    return future.wait();

})(options);

Upvotes: 3

Related Questions