SvenWesterlaken / mongo4j

A mongoose plugin to automatically maintain nodes & relationships in neo4j
https://www.npmjs.com/package/mongo4j
MIT License
14 stars 4 forks source link

If there are two or more Array Nested Ref pluging does not work #76

Closed niktverd closed 4 years ago

niktverd commented 4 years ago

DISCLAIMER: it is on my version of a save file.

Dear SvenWesterlaken

I have schema

const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const mongoosastic = require("mongoosastic");
// const { schema } = require("./partNode");
const mongo4j = require("./plugins/mongo4j");
mongoose.set("debug", false);

// const NestedItemSchema = Schema({
//     id: { type: Schema.Types.ObjectId },
//     relScore: { type: Number, es_type: "long" },
// });

const PartanSchema = Schema(
    {
        desc: { type: String, es_indexed: true, neo_prop: true },
        metaDesc: { type: String, es_indexed: true },
        // mf: [
        //     {
        //         id: {
        //             type: Schema.Types.ObjectId,
        //             ref: "carModif",
        //             es_indexed: true,
        //             neo_rel_name: "MF_PT",
        //         },
        //         score: Number,
        //     },
        // ],

        gp: [
            {
                id: {
                    type: Schema.Types.ObjectId,
                    ref: "genPart",
                    es_indexed: true,
                    neo_rel_name: "GP_PT",
                },
                score: Number,
            },
        ],
    },
    { collection: "partan" }
);

PartanSchema.plugin(mongoosastic, {
    index: "partans",
    hosts: ["localhost:9200"],
    hydrate: true,
    hydrateOptions: { lean: true },
});
PartanSchema.plugin(mongo4j.plugin());

module.exports = mongoose.model("partan", PartanSchema);

// _id  name    partNumber  partSections    catalogs    analogsGroup

if I use only mf Array it works ok. It builds all the necessary nodes and relationships; if I use only gp Array it works ok. It builds all the necessary nodes and relationships;

if I use both of them i get:

Neo4jError: Invalid input 'o': expected 'e/E' (line 3, column 257 (offset: 414))
"    ON MATCH SET doc.desc = 'тормозные колодки передние', doc.m_id = '5f9126b446cd8821bedf1a1b' WITH doc MATCH (I:Carmodif) WHERE I.m_id = '5f8e73cb62b1144467547ac7' MERGE (doc)-[r:MF_PT]->(I)  ON CREATE SET  r.score = 100 ON MATCH SET  r.score = 100WITH doc MATCH (II:Genpart) WHERE II.m_id = '5f8ebaa162b1144467547acf' MERGE (doc)-[r:GP_PT]->(II)  ON CREATE SET  r.score = 100 ON MATCH SET  r.score = 100"
                                                                                                                                                                                                                                                                 ^

    at captureStacktrace (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/neo4j-driver/lib/result.js:277:15)
    at new Result (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/neo4j-driver/lib/result.js:68:19)
    at Session._run (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/neo4j-driver/lib/session.js:174:14)
    at Session.run (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/neo4j-driver/lib/session.js:135:19)
    at Object.one (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/mongo4j/lib/save.js:30:13)
    at model.<anonymous> (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/mongo4j/lib/core.js:31:51)
    at callMiddlewareFunction (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/kareem/index.js:482:23)
    at next (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/kareem/index.js:193:9)
    at next (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/kareem/index.js:212:9)
    at Kareem.execPost (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/kareem/index.js:217:3)
    at _cb (/home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/kareem/index.js:307:15)
    at /home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/mongoose/lib/model.js:407:5
    at /home/nikolay/code/nodejs/servers/elasticSearchSandbox/node_modules/mongoose/lib/model.js:329:11
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'Neo.ClientError.Statement.SyntaxError'
}

and it seems to me that problem could be in Cypher Query building

Neo4jError: Invalid input 'o': expected 'e/E' (line 3, column 257 (offset: 414))
"    ON MATCH SET doc.desc = 'тормозные колодки передние', doc.m_id = '5f9126b446cd8821bedf1a1b' WITH doc MATCH (I:Carmodif) WHERE I.m_id = '5f8e73cb62b1144467547ac7' MERGE (doc)-[r:MF_PT]->(I)  ON CREATE SET  r.score = 100 ON MATCH SET  r.score = 100WITH doc MATCH (II:Genpart) WHERE II.m_id = '5f8ebaa162b1144467547acf' MERGE (doc)-[r:GP_PT]->(II)  ON CREATE SET  r.score = 100 ON MATCH SET  r.score = 100"
                                                                                                                                                                                                                                                                 ^

As you can see it combines 2 queries in one.

Probably you will face the same issue when start to refactor code.

SvenWesterlaken commented 4 years ago

I indeed faced some errors but managed to clear them out. You can reopen this issue if it persists after the upcoming update.

SvenWesterlaken commented 4 years ago

:tada: This issue has been resolved in version 3.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: