Meteor:不同的集合,不同的数据库 [英] Meteor: Different collections, different databases

查看:41
本文介绍了Meteor:不同的集合,不同的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站将有两种类型的用户:客户和管理员.他们都需要账户.对于帐户,内置的流星帐户系统使用 users 集合.有什么方法可以将这两种类型的用户分成单独的集合(例如,customersadmins),而不是将它们全部放在一个集合中?我可能还希望将这些类型的用户放在不同的数据库中(在不同的服务器上):一个数据库用于 customers,另一个用于 admins.那么,如何告诉 Meteor 哪个数据库用于哪个集合?

My site will have two types of users: customers and admins. They all need accounts. And for accounts the built-in meteor accounts system makes use of the users collection. Are there any ways to separate these two types of users into separate collections (say, customers and admins) rather than have them all in that one single collection? I might also want to have these types of users in separate databases (on different servers): one database for customers and the other one for admins. So, how to tell Meteor which database to use for which collection?

这是一种电子商务类型的网站.谁能告诉我为什么一个集合更适合客户和管理员使用?在创建网上商店时使用一个集合而不是两个集合的优缺点是什么?

It's an e-commerce type of site. Can anyone tell me why one single collection would be better to use for both customers and admins? What are the pros and cons of using one collection instead of the two when creating a web shop?

推荐答案

为什么不将您的流星分成 2 个实例,一个用于您的客户端,另一个用于您的管理界面.就我个人而言,我会使用角色,但如果这是您的偏好,那也没什么错:

Why not split your meteor into 2 instances, one for your client and one for your administration interface. Personally I would use roles but there isn't much wrong if this is you're preference:

您的管理流星客户端 js 代码

OtherMeteor = Meteor.connect("http://other_meteor_url")

//get user with username "admin"/connect to a custom method
OtherMeteor.call("getuser",{username:admin}, function(err,result) {
    console.log("result")
})

或者你可以直接附加到另一个流星实例上的集合

OR you could directly attach to a collection on another meteor instance

remote_meteor = Meteor.connect("http://other_meteor_url");
users2 = new Meteor.Collection("users", {manager: remote_meteor})

//wait for the subscription to finish first then use:
console.log(users2.find().fetch())
users2.up

在另一个具有自定义功能的流星中编写代码:

Code in the other meteor that does custom functionality:

服务器js:

Meteor.methods({
    'getuser':function(query) {
        return Meteor.users.find(query).fetch();
    },
    'updateuser':function(query,modifier) {
        return Meteor.users.update(query,modifier);
    }
})

这篇关于Meteor:不同的集合,不同的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆