In Meteor.js, use multiple MongoInternals.RemoteCollectionDriver with the same collection name

MongoInternals.RemoteCollectionDriver("mongodb://#{server.ip}:#{server.port}/#{server.dbName}")

If I call several remote MongoDB methods, and if there are identical names, Meteor throws an error something like this: "collectionName / insert already exists ..."

I think Meteor creates each collection method internally to manage each collection, but I need to control several MongoDBs at a time for some reason.

How can I avoid this situation?

Also, I understand that I can use the Npm Mongo driver directly, without using the NPM package.

var MongoClient = MongoInternals.NpmModules.mongodb.module.MongoClient;

// Connection URL
var url = 'mongodb://localhost:27017/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
  console.log("Connected correctly to server");
  try {
    var collection = db.collection('documents');
    collection.find({}).toArray(function(err, docs){
      console.log(err);
      console.log(docs);
    });
  }
  catch(err) {
    console.log(err);
  }
  db.close();
});

But it still makes me control every DB using the Node.js. callback style Is there any idea to avoid this?

+4
source share
1

, .

, , :

storageServerDriver = new MongoInternals.RemoteCollectionDriver("mongodb://ip:port/dbName")

@Collection = new Mongo.Collection("collection", { _driver: storageServerDriver })

, , , ( Meteor , ).

, , :

storageServerDriver = new MongoInternals.RemoteCollectionDriver("mongodb://ip:port/dbName")

@CollectionTwo = storageServerDriver.open('collection') 
+4

Source: https://habr.com/ru/post/1626819/


All Articles