Need to insert data in Neptune database using gremlin in nodejs codebase

0

Hi, I am trying to insert the in neptune through nodejs API using gremlin however when I am trying to insert nested array of object I keep getting error-599 (server error). Below I am mentioning the controller, data to be inserted and error. I would request to please check fix my controller or tell me what exactly needs to be fixed.

Controller

const gremlin = require('gremlin');
const { DriverRemoteConnection } = gremlin.driver;
const { Graph, __, T } = gremlin.structure;
const { v4: uuidv4 } = require('uuid');

const dotenv = require('dotenv');
dotenv.config();

const ClusterEndpoint = process.env.CLUSTER_ENDPOINT;
const Port = 8182;

const dc = new DriverRemoteConnection(`wss://${ClusterEndpoint}:${Port}/gremlin`, {});

const graph = new Graph();
const g = graph.traversal().withRemote(dc);
module.exports.insertNode = async (req, res) => {
  try {
    const data = req.body;
    console.log(data);

    for (const entry of data.data) {
      const vertex = g.addV('Document').property('label', data.label);

      for (const [key, value] of Object.entries(entry)) {
        if (typeof value !== 'object') {
          // Handle simple properties
          vertex.property(key, value);
        } else {
          // Handle nested properties
          const nestedVertex = g.addV(key);
          for (const [nestedKey, nestedValue] of Object.entries(value)) {
            nestedVertex.property(nestedKey, nestedValue);
          }
    // Add the nested vertex
    const nestedVertexResult = await nestedVertex.next();
    
    // Add the edge
    await vertex.addE('Has' + key).to(nestedVertexResult.value).next();
        }
      }

      await vertex.next();
    }

    console.log('Data inserted successfully.');
  } catch (error) {
    console.error('Error inserting data:', error);
  } finally {
    // Ensure to close the connection properly
    await dc.close();
  }
};

Error

Error inserting data: ResponseError: Server error: {"requestId":"1540dfa7-a2aa-44a1-990a-f3af5fad9523","code":"InternalFailureException"} (599)
    at Connection._handleMessage (/home/rajat.mahajan_ext/Downloads/neptune-Service/node_modules/gremlin/lib/driver/connection.js:345:9)
    at WebSocket.<anonymous> (/home/rajat.mahajan_ext/Downloads/neptune-Service/node_modules/gremlin/lib/driver/connection.js:141:43)
    at WebSocket.emit (events.js:376:20)
    at Receiver.receiverOnMessage (/home/rajat.mahajan_ext/Downloads/neptune-Service/node_modules/ws/lib/websocket.js:1209:20)
    at Receiver.emit (events.js:376:20)
    at Receiver.dataMessage (/home/rajat.mahajan_ext/Downloads/neptune-Service/node_modules/ws/lib/receiver.js:576:14)
    at /home/rajat.mahajan_ext/Downloads/neptune-Service/node_modules/ws/lib/receiver.js:534:12
    at /home/rajat.mahajan_ext/Downloads/neptune-Service/node_modules/ws/lib/permessage-deflate.js:309:9
    at /home/rajat.mahajan_ext/Downloads/neptune-Service/node_modules/ws/lib/permessage-deflate.js:392:7
    at afterWrite (internal/streams/writable.js:466:5) {
  statusCode: 599,
  statusMessage: '{"requestId":"1540dfa7-a2aa-44a1-990a-f3af5fad9523","code":"InternalFailureException"}',
  statusAttributes: Map(0) {}
}

Data to be inserted

{
    "status": true,
    "page": 1,
    "per_page": 100,
    "total_count": 2,
    "last_runtime": "2023-07-12T08:06:25.867000",
    "data": [
      {
        "doc_id": "014afd83-c14c-4722-8db8-96b479f65c3e",
        "changes_viewed": true,
        "case_id": "AVE-1515",
        "query_id": "71ccf54e-7b03-4d01-bae3-c8a4d61bb001",
        "doc_hash": -1989209532,
        "timestamp": "2023-07-12T08:06:25.902502Z",
        "status": "added",
        "saved": false,
        "identifier": "new",
        "elastic_id": "XJAjSYkBsN_giujMH9F0",
        "officer": {
          "id": 408330638,
          "uid": "08856538",
          "name": "VIPUL SHIVA KANT MISHRA",
          "jurisdiction_code": "in",
          "position": null,
          "retrieved_at": "2023-06-06T21:03:38+00:00",
          "opencorporates_url": "https://opencorporates.com/officers/408330638",
          "start_date": "2020-08-31",
          "end_date": null,
          "occupation": null,
          "current_status": null,
          "inactive": null,
          "address": null,
          "nationality": null,
          "date_of_birth": null,
          "company": {
            "name": "SEMICOLON INTERNET LLP",
            "jurisdiction_code": "in",
            "company_number": "AAT-6034",
            "opencorporates_url": "https://opencorporates.com/companies/in/AAT-6034"
          }
        },
        "neo_date": [
          "2020-08-31",
          "2023-06-06T21:03:38+00:00"
        ],
        "neo_location": [],
        "neo_person": [
          "VIPUL SHIVA KANT MISHRA"
        ],
        "neo_organisation": [
          "SEMICOLON INTERNET LLP"
        ],
        "monitoring_status": false
      }],
    "label": "L1(es)"
  }
  • Hello - It's hard to know what might be going wrong just from looking at the error message above. Are you able to open a support case so that we can take a deeper look into what might be going on? One thing to be aware of is that Neptune does not support storing null values. If you need a property to be present even when it contains no data, perhaps explore something like storing an empty string. In general, it's better to just not create the property at all when it has no value. Not present essentially implies null.

Dev
질문됨 4달 전383회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠