小编use*_*987的帖子

使用update()获取受影响文档的ID

我用它来做一个upsert:

Articles.update(
    { title: title },
    { 
        title: title,
        parent: type
    },
    { upsert: true }, 
    function(res) {
        return console.log(res);
    }
);

console.log(needToGetID);
Run Code Online (Sandbox Code Playgroud)

现在我需要获取已更新或插入的文档的_id.我以为我可以通过回调得到它,但是res未定义.我假设只有一个由查询定义的唯一文档.

更新

忘记提到我正在使用流星......

mongodb meteor mongodb-query

7
推荐指数
1
解决办法
4624
查看次数

具有alanning的meteor-app中的结构角色管理:角色

我需要一些建议,以便在我的meteor-app中构建正确的角色架构和管理.

结构体

  • 我正在使用alanning:roles@1.2.13添加角色管理功能的应用程序.
  • 有四种不同的用户类型:管理员,编辑者,专家和用户.
  • 此外,还有几个具有不同内容的模块,即汽车,数学和图像.每个模块都是用自己的流星包组织的.
  • 在每个模块中都有几个类别,可以由编辑者动态添加.

模块中的类别

模块的结构如下:

elementSchema = new SimpleSchema({ 
    element:    {type: String, optional: true}
});

Cars.attachSchema(new SimpleSchema({
    title:      { type: String },
    content:    { type: String },
    category:   { type: [elementSchema], optional: true },
});
Run Code Online (Sandbox Code Playgroud)

如您所见,所有可用类别都在模块的Collection中.

  • 管理员:完整权利
  • 编辑:可以编辑所选模块中的元素(即editor_1可以编辑汽车和图像中的元素,但不能编辑数学中的元素)
  • 专家:可以获得完整模块的权利,也可以只获得模块的某些类别(即)expert_1可以编辑图像,但只能使用汽车中"本田"和"梅赛德斯"类别中的元素; 没有编辑数学)
  • 用户:没有编辑

这就是我在技术上进行身份验证的方式:

router.js

var filters = {
    authenticate: function () {
        var user;
        if (Meteor.loggingIn()) {
            this.layout('login');
            this.render('loading');
        } else {
            user = Meteor.user();
            if (!user) {
                this.layout('login');
                this.render('signin');
                return;
            }
            this.layout('Standard');
            this.next();
        } …
Run Code Online (Sandbox Code Playgroud)

javascript authentication roles meteor simple-schema

6
推荐指数
1
解决办法
838
查看次数