thingdom/node-neo4j

Can query a node from index

hansman opened this issue · 8 comments

What happens here?

  • create a node
  • save the node
  • index the node
  • get the indexed node

var indexName = 'myNodeIndex';
var node = db.createNode({name: 'hey'});
node.save(function() {
db.index(indexName, 'name', 'hey', function() {
db.getIndexedNode(indexName, 'name', 'hey', console.log)
})
})

Expected:
getIndexedNode returns the node that just got indexed.

Actual:
getIndexedNode has empty response

You're passing console.log as a callback directly. Can you instead pass a proper function (err, node) { console.log(node); } callback? Does that work?

The other thing is, you're not seeing if you're getting any errors. For each of the callbacks, it's good to check if (err) throw err; where err is the first param.

For sure. This code is only to point out the flow. console.log is sufficient to see that there is an empty response which is the point of this demonstration.

Got it. Would you mind confirming a couple things for sanity:

  • You write db.index, but your code is actually node.index, right?
  • There are no errors returned for any of these calls, incl. node.index?

Assuming both of these are indeed the case:

  • What happens if you check the index after some delay (e.g. a few seconds)? Does it show up? If so, it would seem that Neo4j legacy indexes are eventually consistent, not immediate. I don't know anything about that, though; might check with the Neo4j mailing list or Slack.
  • You might already be aware of this, but could you use Neo4j v2 schema indexes? Those are immediately consistent, I'm pretty sure.

no errors. yes I use node.index. I can't get the node from the index even after a long delay. Not a eventual consistency case.

question: have you tried doing this yourself?

Okay, surprising.

No, I haven't tried this myself. We use exclusively v2 schema indexes and legacy auto-indexes, not legacy manual indexes. I can try myself later.

Another thing to try would be using the Neo4j webadmin to do these things manually. Does it work there? If so, suggests a node-neo4j or code bug. If not, suggests a Neo4j bug.

However, we do cover manual indexing in our tests, and that's always worked:

'index nodes': (_) ->
daniel.index 'users', 'name', 'Daniel', _
node = db.getIndexedNode 'users', 'name', 'Daniel', _
expect(node).to.be.an 'object'
expect(node.exists).to.be.true