Question: jion tow object on keys,then insert one to another


#1

hi:
I query via NIQL statements:

    select 
    OBJECT_CONCAT({"adminId": adm},{"logs":logs})
    FROM lesson as logs
    JOIN lesson AS adm ON KEYS logs.adminId

return:

[
  {
    "$1": {
      "adminId": {
        "createdTime": 1534333674040,
        "departmentId": "Department::1534333631008::japq",
        "isSuper": true,
        "mobile": "test Admin",
        "name": "test Admin",
        "password": "test Admin",
        "type": "Admin",
        "username": "test Admin"
      },
      "logs": {
        "adminId": "Admin::1534333674040::468r",
        "classId": "Class365::1534142979269::e3wm",
        "createdTime": 1534405376506,
        "description": "this is a first desc",
        "type": "AdminLogs"
      }
    }
  }
]

I want to replace logs object adminId property with adminId object.

like this:

[
  {
      "logs": {
        "adminId": {
            "createdTime": 1534333674040,
            "departmentId": "Department::1534333631008::japq",
            "isSuper": true,
            "mobile": "test Admin",
            "name": "test Admin",
            "password": "test Admin",
            "type": "Admin",
            "username": "test Admin"
         },
        "classId": "Class365::1534142979269::e3wm",
        "createdTime": 1534405376506,
        "description": "this is a first desc",
        "type": "AdminLogs"
      }
    }
]

how does it?

thanks for your reply.

best regards!


#2
select 
    OBJECT_PUT(logs,"adminId",adm) AS logs
    FROM lesson as logs
    JOIN lesson AS adm ON KEYS logs.adminId

#3

@vsr1

great! thank you very much!


#4

hi @vsr1
this statement works for me when joining two objects.

select 
    OBJECT_PUT(OBJECT_PUT(logs,"adminId",adm),"classId", class)
    FROM guoxue as logs
    JOIN guoxue AS adm ON KEYS logs.adminId
    JOIN guoxue as class ON KEYS logs.classId

Is this N1QL right?

best regards!


#5

It is right.

You can also try this, If format works out.

SELECT
    logs.*, adm AS adminId, class AS classId
    FROM lesson as logs
    JOIN lesson AS adm ON KEYS logs.adminId
    JOIN guoxue as class ON KEYS logs.classId;

#6

hi:

this N1QL statement is clear logic, thanks~~