Recently I have a requirement to be able to implement a MeteorJS application capable of connecting to different databases according to the connected user.
The structure of the database is the same, only the information it contains changes
I tried connecting through DDP to another backend connected to the necessary database and also by using MongoInternals but, although the users log in correctly, the other collections continue to consult the database by default.
In the server code
const connection = DDP.connect(url)
Accounts.connection = Meteor.connection = connection
_.each(
[
"subscribe",
"methods",
"call",
"apply",
"status",
"reconnect",
"disconnect",
],
function (name) {
Meteor[name] = _.bind(Meteor.connection[name], Meteor.connection); // 55
}
);
ConfigApps = new Mongo.Collection("configapps")
Here the ConfigApps collection obtains the correct data from the database but from the Frontend the data from the other database is read
Or:
var database = new MongoInternals.RemoteCollectionDriver(
"mongodb://localhost:27017/spence-local"
);
ConfigApps = new Mongo.Collection("configapps", {
_driver: database,
_suppressSameNameError: true,
});
Meteor.users = new Mongo.Collection("users", {
_driver: database,
_suppressSameNameError: true,
});
With the same results. User can connect but only one database is read for all querys in the application
Some information or clue would be great.