MongoDB关系管理

时间:2015-05-26 09:37:48

标签: mongodb

我有一个问题,我有两个集合,用户和角色,我拥有用户自己的文档(SystemRoles属性)的角色。 如果有关于角色定义的更新,那么如何更新用户的角色信息,或者让我管理更专业的人来解决这个问题?

示例用户文档:

"_id" : ObjectId("55606cf9a6df191510963a3b"),
    "CreationDate" : ISODate("2015-05-23T12:05:13.110Z"),
    "IsActive" : true,
    "Provider" : null,
    "FirstName" : "admin",
    "LastName" : "admin",
    "BirthDay" : ISODate("1984-08-18T21:00:00.000Z"),
    "Gender" : null,
    "ImageUrl" : "~/Images/avatar.png",
    "ActorId" : ObjectId("55606cf9a6df191510963a39"),
    "DepartmentName" : "Ana Kurum",
    "DepartmentId" : ObjectId("55606cf9a6df191510963a38"),
    "SystemRoles" : [ 
        {
        "_id" : ObjectId("55643948a6df1915a88717a4"),
        "CreationDate" : ISODate("2015-05-26T09:13:44.287Z"),
        "IsActive" : true,
        "Name" : "Administrator",
        "Path" : "\\",
        "TypeId" : 3,
        "ParentActorId" : null
    }, 
    {
        "_id" : ObjectId("55643948a6df1915a88717a5"),
        "CreationDate" : ISODate("2015-05-26T09:13:44.392Z"),
        "IsActive" : true,
        "Name" : "User",
        "Path" : "\\",
        "TypeId" : 3,
        "ParentActorId" : null
    }
    ],

1 个答案:

答案 0 :(得分:0)

MongoDb不提供对多个集合之间关系的任何支持。它与数据库的sql方法不同。 No-sql支持由架构设计本身维护的逻辑关系。它的基本目标是减少对部分文档的依赖并加速该过程。

"address": [
      {
         "building": "22 A, Indiana Apt",
         "pincode": 123456,
         "city": "Los Angeles",
         "state": "California"
      },
      {
         "building": "170 A, Acropolis Apt",
         "pincode": 456789,
         "city": "Chicago",
         "state": "Illinois"
      }]

对于演示示例,您可以访问What process is listening on a certain port on Solaris?