Updating a node and its accompanying indexes in neo4j using neography - neo4j

How do I update a given property of a node using neography? And if its an indexed field. will the indexes get updated automatically?
I know on the console, its as trivial as
cd -a 15
set username foobar
Of course this doesnt update any indexes(indices sp?) either.

According to the neo4j-manual-1.8
To update an index entry, the old one must be removed and a new one
added
Another option is to setup autoindexing.

Related

Merge two nodes on session.save (unique nodes)

I'm trying to map some JSON objects to java objects and then save these objects to my neo4j db.
I have tried to use simple neo4j-ogm and run: session.save(object), but if some nodes already exist they are duplicated instead of being merged.
If I create a unique constraint on the value, then I get an exception when I try to run: session.save(object) if the nodes already exists.
I would like to know if there is a solution using neo4j-ogm, or i need to add Spring Data Neo4J (SDN) to resolve this problem?
As of Neo4j OGM 2.1.0, you can use #Index for this.
Annotate your field with #Index(unique=true, primary=true) and session.save will use a MERGE instead of CREATE
See http://neo4j.com/docs/ogm-manual/current/reference/#reference_programming-model_indexing in the docs

(Neo4j.rb) Each call of on properties of a node triggers a query to the database

Here's the problem
A query is trigger every time when a node property is called in the view
How it looks in the view
But even when a query was done to retrieve all the nodes it still sends one query for each property. Is there something that I overlooked in retrieving the nodes or there is a design flaw in the way I programmed the app.
What version of the neo4j gem are you using? The latest versions should address this.
The new gems don't introduce many breaking changes (see the CHANGELOG), but if, for some reason, you can't upgrade you can set the following configuration in config/application.rb:
config.neo4j._active_record_destroyed_behavior = true

ROR maintain history of object updates

I have a model which I want to store a history of changes to, my plan is to rather than update an object create a new one and on a show only fetch the latest version.
This plan presents a number of difficulties firstly the id will be different after a update I indend to get around this by keeping a second ID column which will be the same for all updates of that instance.
to that end I have created a SQLite sequence for this second coloumn.
my question is how can I get values from this sequence in the model/controller as I will only want to get from it on first time the object is created, secondly how can I use this second ID column as the URL for the object so it is fixed throughout updates.
Many Thanks,
Check out the PaperTrail gem. It might do what you want and sidestep those issues completely.
https://github.com/airblade/paper_trail

ServerPlugins in Neo4j 2.0.0-M03: Where to create schema index

I'm going to check out the new automatic indexing capabilities that come with Neo4j 2.0. They are described here: http://docs.neo4j.org/chunked/2.0.0-M03/tutorials-java-embedded-new-index.html
Now the automatic index must created at one point. The old way to get an index was just "indexManager.forNodes()" and the index was returned if existing, created if not. With automatic indexing, we just have to create the index once via "schema.indexFor()..." and then be done with it.
My question is, where do I best put the index creation? In the documentation example, they have a main method. But I'm working with a ServerPlugin. I'd like to create the indexes once at startup, if they do not already exist. But where can I do this? And how to I check whether the index already exists? I can get all IndexDefinition for a label. But since an IndexDefinition may depend on a label and on a arbitrary property, I would have to iterate through all IndexDefinitions for a specific label and check whether the one with the correct property does exist.
I could of course simply do what I just wrote, but it seems a bit cumbersome compared to the old index handling which would check automatically whether the requested index exists and create it, if not. So I'm wondering if I simply missed some key points with the handling of the new indices.
Thank you!
I got a response from a Neo4j dev here: http://docs.neo4j.org/chunked/2.0.0-M03/tutorials-java-embedded-new-index.html
He proposes to create the automatic indexes in a neo4j start script, for instance. I also saw that someone already wished for unique indexes (would be a great feature!). That would simplify the index creation but in the end this is now a part of the database setup, it seems.

Scaffolding user ID resetting

in the application i am currently creating in ruby on rails. I am trying to do some tests in rails console where i have to destroy data in the database and the database is connected to a server. I am importing an XML and parsing it and putting it into a database with scaffolding.
Now what i need: Basically what i am attempting to do is to destroy the data and replace it with a new one every week..but the problem i am getting, the userid is gone up to 700+ and there are only 50 records :S cause it doesnt reset...
To delete all records i am currently using "whatever.destroy_all" does the trick
Any help?
Btw i am using SQLITE
The ID column created in the table usually is set as unique and to increment by 1 for each new record, which is why each time you destroy and add new data the ID keeps getting higher.
The fact that the ID # is getting larger and larger is not an issue at all.
If you really want to start back at zero, I would think you could drop the table and recreate it, but that seems like overkill for a trivial issue.
Regarding the connection to the other scaffold, how are you connecting the two and what do they both represent?
Ideally the data population for testing should be done through fixtures (or easy tools such as factorygirl etc..)
The main advantage of having a fix data set is you can run your tests in any environment. But as per your requirement you can do something like this,
When you populate the date through the active records pass the id parameter as well
Ex: User.new(:id => 1, :name => "sameera").create
By this way you can have constant id's But make sure you increment the id accordingly.

Resources