Neode - Object Graph Mapper for Node JS

Neode is a Neo4j OGM for Node JS designed to take care of the CRUD boilerplate involved with setting up a neo4j project. The idea is to reduce the amount of code it takes to start a Neo4j project in with node. Just set up your models, create a Neode instance in your project and off you go...

I wrote an article on Medium explaining my inspiration and how to get started.

If you have any problems or have feedback, feel free to reply here or open up an issue. Pull Requests are also more than welcome.

Main Repository: GitHub - adam-cowley/neode: Neo4j OGM for Node.js
Example Project: GitHub - adam-cowley/neode-example: An example project using Neode

Happy coding!

4 Likes

Hi @adam_cowley I was wondering if you have any examples of your OGM creating relationships between 2 nodes. I have been trying to see if I can use your OGM to achieve this without having to write a cypher.

Thanks

1 Like

Hi Ben,

At the moment you would need to do something like the following. It's not ideal but this assumes that you need to load the two nodes.

const person1 = neode.find('Person', id1);
const person2 = neode.find('Person', id2);

person1.relateTo(person2, rel_type, properties)
  .then(rel => console.log(rel.id)

Or if you don't have the nodes loaded, you could pass through the information into a merge call:

neode.merge('Person', {
  id: 1,
  knows: [ {id: 2} ]
})

Let me know if that helps.

1 Like

so using knows as the relationship or would we have to explicitly define this in the Model.

module.exports: {
...knows : {
}
}

I would definitely be interested in using both methods but at the moment I am just getting to grips to define the relationships. I will let you know how I get on thanks

Knows would need to be defined in both scenarios. What are you trying to do? It would be easier to advise if I know what you're trying to do.

Might as well thanks for the help :) . I am trying to construct a test project, it's a population management system. In the system, you define parent locations and any subsequent child locations defined are nested in their parents. And so on.

I defined the model as

module.exports = {
labels: ["Location"],

name: {
type: 'string',
unique: 'true', // Creates a Unique Constraint
},

id: {
primary: true,
type: 'uuid',
required: true, // Creates an Exists Constraint in Enterprise mode
},
malePopulation: {
type: 'number',
},
femalePopulation: {
type: 'number',
},
totalPopulation: {
type: 'number',
},
located_in: {
type: "relationship",
target: "Location",
relationship: "LOCATED",
direction: "in",
properties: {
name: "string"
},
}
}

I am using a Neo4j DB on GrapheneDB. At the moment I have only been able to create the nodes but no relationships. The final aim is to be able to update a child location and for those changes to reflect in the parents e.g. If I had a parent Location called U.S.A with a child New York which also had a child Maine. Updates in Maine and New York would reflect in U.S.A. Thanks for the help

Aren't person1 and person2 Promises? Shouldn't it be:

location1.then(
  (res) => {
    res.relateTo(location2, 'located_in')
      .then(rel => console.log(rel.id))

  }
)

Hi @adam_cowley I having issues with neode, please see what I get when I try to create a node

As you can see when I run the create command using a neode instance the promise didn't resolve sucessfuly, I review also the model and connection settings are right, so I don't know what's wrong, Would you help me?

Thanks for submitting!

I’ve added a tag that allows your blog to be displayed on the community home page!

I don't think the function in the router is asynchronous, I'm not sure whether removing async will solve the problem or not.

You can also use res.toJson() to return a cleaner JSON object with its properties rather than using JSON.stringify.

What version of neode are you using? Do you have a repository that I can clone and take a look at?

Hi, I'm having some trouble understanding what I have to do. I have used:

.with({
    User: require('./models/User'),
    Skill: require('./models/Skill')
  })

And
.schema.install().then(() => console.log('schemas installed')))

But my models don't appear in the db until I create a node of that type?

What does .schema.install() actually do? And do I have to do any .model() commands?

Regards

Hi Adam.
I'm trying to do a simple find and update but having no success.
Based on combining a couple of your examples I expected to code:

instance.first('Person', 'name', 'Adam')
    .then(adam => adam.update({age: 29}));

But this produces the following error:
ValidationError: child "person_id" fails because ["person_id" is required]

When I check the person object in debug it has an id value.

Any assistance would be most welcome.

Sorry for the delay in replying. This is something that has been bugging me for a while. I published 0.3.4 last night which should fix this issue. Let me know how you get on.

Thanks Adam. However, I've gone back to basics.
I'm just using the raw browser version of the Neo4j Driver which is sufficient for my needs now that I've figured out how it works.
I wish you well with this project.

2 Likes

Hi Adam,
I am new to Neo4j (have done a small amount of work using Mongoose on Nodejs) and would like to evaluate Neode using the Neode-example application from GitHub. I have set up a 10 day evaluation of the Neo4j sandbox but am not able to connect to the sandbox database from the example application on my computer. My instance of the sandbox movies database tells me to use the following connection details:
Username:neo4j
Password:pointers-exchange-checkout
IP Address:100.26.209.30
HTTP Port:33969
Bolt Port:33968
Neo4j Browser: https://10.0.1.26-33969.neo4jsandbox.com/
Bolt URL: bolt://100.26.209.30:33968
Websocket Bolt URL: bolt://ws-10-0-1-26-33968.neo4jsandbox.com:443/

In .env file of the Neode-example app I entered:
NEO4J_PROTOCOL=bolt
NEO4J_HOST=bolt://100.26.209.30:33968
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=pointers-exchange-checkout
NEO4J_PORT=33968

What am I doing wrong? Any guidance would be appreciated.
Thanks,
Joel

Hey Joel,

The host should just be the IP address rather than with the protocol and port. Try this line instead:

NEO4J_HOST=100.26.209.30

Thanks, I am now connected but am getting an error: "Neo4jError: Driver is connected to the database that does not support multiple databases. Please upgrade to neo4j 4.0.0 or later in order to use this functionality." Would I be better off loading Neo4j and the database from the sandbox on my computer? I am a newbie on this so don't want to waste a lot of your time.