Table of Contents
Question content
Workaround
Home Java Spring Data Neo4j returns count of affected nodes after update operation

Spring Data Neo4j returns count of affected nodes after update operation

Feb 22, 2024 pm 02:01 PM

php editor Xigua brings the latest java Q&A: How does Spring Data Neo4j return the count of affected nodes after an update operation? Spring Data Neo4j is a powerful graph database framework that provides rich functions and flexible API. When performing an update operation, sometimes it is necessary to obtain the number of affected nodes after the update for subsequent processing. This article will introduce how to use Spring Data Neo4j to implement this function and help developers make better use of the features of graph databases.

Question content

After performing an update operation using the spring data neo4j repository, is there any way to return the number of affected nodes?

For example

@Query("MATCH (n:Student) WHERE n.id IN $idList SET n.isRegistered = true")
Integer updateRegisterInfo(@Param("idList") List<String> idList);
Copy after login

But sdn can only return void/null values ​​for such operations.

Thank you

Workaround

If you want the number of nodes to which set is applied, return the number of rows:

match (n:student) where n.id in $idlist 
set n.isregistered = true
return count(*) as numaffected
Copy after login

If you want a count of nodes with isregistered values ​​that have changed, use the where clause to delete nodes that already have isregistered = true:

MATCH (n:Student) 
WHERE n.id IN $idList AND NOT coalesce(n.isRegistered, false) 
SET n.isRegistered = true
RETURN count(*) AS numAffected
Copy after login

(I just formatted this as a standalone cypher to make it easier to read.)

The above is the detailed content of Spring Data Neo4j returns count of affected nodes after update operation. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)