Meteor - connect collections of multiple databases

徘徊边缘 提交于 2020-01-25 21:10:32

问题


In Meteor (server side), is it possible to create collections of multiple databases?

Let's say I want to connect to two different databases and mount their collections in meteor. My concern are collections with the same name in both databases (for example "users").

Is there any way to have 2 collections named "users" but from 2 different databases (connections)?

Thanks!

EDIT:

The other question does not address my main issue: what if I want to mount (connect) two collections named "users" (for example) from 2 different databases.

Meteor says:

Error: A method named '/users/insert' is already defined


回答1:


I reopened the question, but there is no easy answer. The mongo driver assumes one connection per collection. As an aside, this is a reasonable assumption - if you did a write, which DB would be updated?

Here are some ways you could work around this limitation without implementing your own driver:

  1. Declare more than one collection (Users1 and Users2), where each collection has access to one of the database instances. Technically this would work fine, but may not be easy to do in your code.

  2. Use an external process to regularly copy the contents of one collection from db1 to db2. This lets you use a single collection, but could get complicated if some of the documents are being written from external applications.

  3. Only use methods to access the data instead of publishing it to the client. You lose the ability to have collection semantics on the client, but you can directly control how the database is used. Also see the answers to this question for some examples of how to directly use an instance of RemoteCollectionDriver.



来源:https://stackoverflow.com/questions/33464238/meteor-connect-collections-of-multiple-databases

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!