MongoInternals is not defined error


#1

Can anyone help me identify why I am getting this error “MongoInternals is not defined”?

I have two files:

a.js:

var database = new MongoInternals.RemoteCollectionDriver("mongodb://127.0.0.1:3001/meteor");
Boxes = new Mongo.Collection("boxes", { _driver: database });

if (Meteor.isServer) {
	Meteor.publish('boxes', function() {
  		return Boxes.find(); 
	});	
}

b.js:

if (Meteor.isClient) {
	
	Meteor.subscribe('boxes');
	
	Template.homeCanvasTpl.helpers({
		my_boxes: function () {
			return Boxes.find({});
		}
	});	
}

#2

I’ve been looking through the source and am also trying to get this working. MongoInternals.RemoteCollectionDriver needs to be called on the server only, which is the source of the console error. Log database and post the result


#3

@tidee MongoInternals is a server-side method, you client code shouldn’t be aware of your database connection. Client receives data through DDP using publish/subscribe.

Try this:

a.js

 if (Meteor.isServer) {
   var database = new MongoInternals.RemoteCollectionDriver("mongodb://127.0.0.1:3001/meteor");
   Boxes = new Mongo.Collection("boxes", { _driver: database });
   Meteor.publish('boxes', function() {
     return Boxes.find();   
   });                      
 }

b.js

if (Meteor.isClient) {
  Meteor.subscribe('boxes');
  Boxes = new Mongo.Collection("boxes");
}

#4

Yup, this works - thanks you so much. Is there any documentation on this?


#5

Given the approach is setting an internal property of the options Mongo Collection constructor, it’s acceptable for there to be no documentation, but the source is readable ahead of a public api


#6

I have the follwing error: “MongoInternals is not defined”

I have a file with the collection definitions in /imports/api/module/module.js
In my client side called the module file that export the collection (imports/ui/module/module).

How i can resolve this error.

Thks