Can I SET a map in Neo4j Cypher without overwriting existing properties
I have a map say
car: {make: toyota, color: blue, model: camry}
and I have a node Car with the property
make: toyota
Now I want to add the properties in the map car to my node Car.
However,
MATCH (n:Car {make:'toyota'})
SET n +=car
RETURN n;
will overwrite the make property on my node.
Is there a way I can avoid it doing this?
The use case is when make is the key property for the node I wouldn't want it to be accidentally changed and of course I wouldn't want to trow an error either.
neo4j cypher
add a comment |
I have a map say
car: {make: toyota, color: blue, model: camry}
and I have a node Car with the property
make: toyota
Now I want to add the properties in the map car to my node Car.
However,
MATCH (n:Car {make:'toyota'})
SET n +=car
RETURN n;
will overwrite the make property on my node.
Is there a way I can avoid it doing this?
The use case is when make is the key property for the node I wouldn't want it to be accidentally changed and of course I wouldn't want to trow an error either.
neo4j cypher
Of Interest: Mutate specific properties using a map and +=
– Guy Coder
Nov 20 at 16:42
add a comment |
I have a map say
car: {make: toyota, color: blue, model: camry}
and I have a node Car with the property
make: toyota
Now I want to add the properties in the map car to my node Car.
However,
MATCH (n:Car {make:'toyota'})
SET n +=car
RETURN n;
will overwrite the make property on my node.
Is there a way I can avoid it doing this?
The use case is when make is the key property for the node I wouldn't want it to be accidentally changed and of course I wouldn't want to trow an error either.
neo4j cypher
I have a map say
car: {make: toyota, color: blue, model: camry}
and I have a node Car with the property
make: toyota
Now I want to add the properties in the map car to my node Car.
However,
MATCH (n:Car {make:'toyota'})
SET n +=car
RETURN n;
will overwrite the make property on my node.
Is there a way I can avoid it doing this?
The use case is when make is the key property for the node I wouldn't want it to be accidentally changed and of course I wouldn't want to trow an error either.
neo4j cypher
neo4j cypher
edited Nov 20 at 16:32
Guy Coder
14.9k43982
14.9k43982
asked Nov 20 at 16:27
MichaelE
233113
233113
Of Interest: Mutate specific properties using a map and +=
– Guy Coder
Nov 20 at 16:42
add a comment |
Of Interest: Mutate specific properties using a map and +=
– Guy Coder
Nov 20 at 16:42
Of Interest: Mutate specific properties using a map and +=
– Guy Coder
Nov 20 at 16:42
Of Interest: Mutate specific properties using a map and +=
– Guy Coder
Nov 20 at 16:42
add a comment |
2 Answers
2
active
oldest
votes
If you try to do this in one query, you will have to make one WHERE clause that catches all of the properties that are NULL. From that you would need to use a WITH clause to pass on those records and use another WHERE clause to select just the records missing one property. The problem is getting back to the records from the first WHERE clause. That may be possible but if so I don't know how to do that with Cypher.
Using multiple queries for each property this is easily done by adding an IS NULL to the WHERE clause.
To demonstrate this a set of records with different combinations of properties set and missing are created.
CREATE (:Car {make: "toyota", color: "red", model: "prius", car_id: 01} )
CREATE (:Car {make: "toyota", color: "red", car_id: 02} )
CREATE (:Car {make: "toyota", model: "prius", car_id: 03} )
CREATE (:Car {make: "toyota", car_id: 04} );
To see what was created
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │null │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │null │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
To update just the color property
MATCH (c:Car {make:"toyota"})
WHERE c.color IS NULL
SET c += {color: "blue"}
RETURN c;
and to see what changed
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
Notice that just the cars with no color property are updated.
Doing the same for model
MATCH (m:Car {make:"toyota"})
WHERE m.model IS NULL
SET m += {model: "camry"}
RETURN m;
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
add a comment |
You can use apoc.map.clean to remove certain keys and values from a map:
SET c += apoc.map.clean(car, ['make'],)
So this would leave the car property [make] undisturbed? basically is the apoc removing 'make' from the map before executing the SET?
– MichaelE
Nov 20 at 18:26
Yes. If you want to remove all existing keys from the map (so that the update operation only adds new properties and doesn't overwrite existing properties) you can supply the keys on that node as the keys to remove from the map:SET c += apoc.map.clean(car, keys(c), )
– InverseFalcon
Nov 21 at 9:49
I will test these
– MichaelE
Nov 21 at 22:01
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397349%2fcan-i-set-a-map-in-neo4j-cypher-without-overwriting-existing-properties%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you try to do this in one query, you will have to make one WHERE clause that catches all of the properties that are NULL. From that you would need to use a WITH clause to pass on those records and use another WHERE clause to select just the records missing one property. The problem is getting back to the records from the first WHERE clause. That may be possible but if so I don't know how to do that with Cypher.
Using multiple queries for each property this is easily done by adding an IS NULL to the WHERE clause.
To demonstrate this a set of records with different combinations of properties set and missing are created.
CREATE (:Car {make: "toyota", color: "red", model: "prius", car_id: 01} )
CREATE (:Car {make: "toyota", color: "red", car_id: 02} )
CREATE (:Car {make: "toyota", model: "prius", car_id: 03} )
CREATE (:Car {make: "toyota", car_id: 04} );
To see what was created
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │null │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │null │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
To update just the color property
MATCH (c:Car {make:"toyota"})
WHERE c.color IS NULL
SET c += {color: "blue"}
RETURN c;
and to see what changed
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
Notice that just the cars with no color property are updated.
Doing the same for model
MATCH (m:Car {make:"toyota"})
WHERE m.model IS NULL
SET m += {model: "camry"}
RETURN m;
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
add a comment |
If you try to do this in one query, you will have to make one WHERE clause that catches all of the properties that are NULL. From that you would need to use a WITH clause to pass on those records and use another WHERE clause to select just the records missing one property. The problem is getting back to the records from the first WHERE clause. That may be possible but if so I don't know how to do that with Cypher.
Using multiple queries for each property this is easily done by adding an IS NULL to the WHERE clause.
To demonstrate this a set of records with different combinations of properties set and missing are created.
CREATE (:Car {make: "toyota", color: "red", model: "prius", car_id: 01} )
CREATE (:Car {make: "toyota", color: "red", car_id: 02} )
CREATE (:Car {make: "toyota", model: "prius", car_id: 03} )
CREATE (:Car {make: "toyota", car_id: 04} );
To see what was created
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │null │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │null │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
To update just the color property
MATCH (c:Car {make:"toyota"})
WHERE c.color IS NULL
SET c += {color: "blue"}
RETURN c;
and to see what changed
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
Notice that just the cars with no color property are updated.
Doing the same for model
MATCH (m:Car {make:"toyota"})
WHERE m.model IS NULL
SET m += {model: "camry"}
RETURN m;
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
add a comment |
If you try to do this in one query, you will have to make one WHERE clause that catches all of the properties that are NULL. From that you would need to use a WITH clause to pass on those records and use another WHERE clause to select just the records missing one property. The problem is getting back to the records from the first WHERE clause. That may be possible but if so I don't know how to do that with Cypher.
Using multiple queries for each property this is easily done by adding an IS NULL to the WHERE clause.
To demonstrate this a set of records with different combinations of properties set and missing are created.
CREATE (:Car {make: "toyota", color: "red", model: "prius", car_id: 01} )
CREATE (:Car {make: "toyota", color: "red", car_id: 02} )
CREATE (:Car {make: "toyota", model: "prius", car_id: 03} )
CREATE (:Car {make: "toyota", car_id: 04} );
To see what was created
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │null │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │null │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
To update just the color property
MATCH (c:Car {make:"toyota"})
WHERE c.color IS NULL
SET c += {color: "blue"}
RETURN c;
and to see what changed
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
Notice that just the cars with no color property are updated.
Doing the same for model
MATCH (m:Car {make:"toyota"})
WHERE m.model IS NULL
SET m += {model: "camry"}
RETURN m;
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
If you try to do this in one query, you will have to make one WHERE clause that catches all of the properties that are NULL. From that you would need to use a WITH clause to pass on those records and use another WHERE clause to select just the records missing one property. The problem is getting back to the records from the first WHERE clause. That may be possible but if so I don't know how to do that with Cypher.
Using multiple queries for each property this is easily done by adding an IS NULL to the WHERE clause.
To demonstrate this a set of records with different combinations of properties set and missing are created.
CREATE (:Car {make: "toyota", color: "red", model: "prius", car_id: 01} )
CREATE (:Car {make: "toyota", color: "red", car_id: 02} )
CREATE (:Car {make: "toyota", model: "prius", car_id: 03} )
CREATE (:Car {make: "toyota", car_id: 04} );
To see what was created
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │null │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │null │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
To update just the color property
MATCH (c:Car {make:"toyota"})
WHERE c.color IS NULL
SET c += {color: "blue"}
RETURN c;
and to see what changed
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│null │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
Notice that just the cars with no color property are updated.
Doing the same for model
MATCH (m:Car {make:"toyota"})
WHERE m.model IS NULL
SET m += {model: "camry"}
RETURN m;
MATCH (n) RETURN n.make,n.model,n.color,n.car_id,LABELS(n);
╒════════╤═════════╤═════════╤══════════╤═══════════╕
│"n.make"│"n.model"│"n.color"│"n.car_id"│"LABELS(n)"│
╞════════╪═════════╪═════════╪══════════╪═══════════╡
│"toyota"│"prius" │"red" │1 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"red" │2 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"prius" │"blue" │3 │["Car"] │
├────────┼─────────┼─────────┼──────────┼───────────┤
│"toyota"│"camry" │"blue" │4 │["Car"] │
└────────┴─────────┴─────────┴──────────┴───────────┘
answered Nov 20 at 17:21
Guy Coder
14.9k43982
14.9k43982
add a comment |
add a comment |
You can use apoc.map.clean to remove certain keys and values from a map:
SET c += apoc.map.clean(car, ['make'],)
So this would leave the car property [make] undisturbed? basically is the apoc removing 'make' from the map before executing the SET?
– MichaelE
Nov 20 at 18:26
Yes. If you want to remove all existing keys from the map (so that the update operation only adds new properties and doesn't overwrite existing properties) you can supply the keys on that node as the keys to remove from the map:SET c += apoc.map.clean(car, keys(c), )
– InverseFalcon
Nov 21 at 9:49
I will test these
– MichaelE
Nov 21 at 22:01
add a comment |
You can use apoc.map.clean to remove certain keys and values from a map:
SET c += apoc.map.clean(car, ['make'],)
So this would leave the car property [make] undisturbed? basically is the apoc removing 'make' from the map before executing the SET?
– MichaelE
Nov 20 at 18:26
Yes. If you want to remove all existing keys from the map (so that the update operation only adds new properties and doesn't overwrite existing properties) you can supply the keys on that node as the keys to remove from the map:SET c += apoc.map.clean(car, keys(c), )
– InverseFalcon
Nov 21 at 9:49
I will test these
– MichaelE
Nov 21 at 22:01
add a comment |
You can use apoc.map.clean to remove certain keys and values from a map:
SET c += apoc.map.clean(car, ['make'],)
You can use apoc.map.clean to remove certain keys and values from a map:
SET c += apoc.map.clean(car, ['make'],)
answered Nov 20 at 18:03
Michael Hunger
36.2k33661
36.2k33661
So this would leave the car property [make] undisturbed? basically is the apoc removing 'make' from the map before executing the SET?
– MichaelE
Nov 20 at 18:26
Yes. If you want to remove all existing keys from the map (so that the update operation only adds new properties and doesn't overwrite existing properties) you can supply the keys on that node as the keys to remove from the map:SET c += apoc.map.clean(car, keys(c), )
– InverseFalcon
Nov 21 at 9:49
I will test these
– MichaelE
Nov 21 at 22:01
add a comment |
So this would leave the car property [make] undisturbed? basically is the apoc removing 'make' from the map before executing the SET?
– MichaelE
Nov 20 at 18:26
Yes. If you want to remove all existing keys from the map (so that the update operation only adds new properties and doesn't overwrite existing properties) you can supply the keys on that node as the keys to remove from the map:SET c += apoc.map.clean(car, keys(c), )
– InverseFalcon
Nov 21 at 9:49
I will test these
– MichaelE
Nov 21 at 22:01
So this would leave the car property [make] undisturbed? basically is the apoc removing 'make' from the map before executing the SET?
– MichaelE
Nov 20 at 18:26
So this would leave the car property [make] undisturbed? basically is the apoc removing 'make' from the map before executing the SET?
– MichaelE
Nov 20 at 18:26
Yes. If you want to remove all existing keys from the map (so that the update operation only adds new properties and doesn't overwrite existing properties) you can supply the keys on that node as the keys to remove from the map:
SET c += apoc.map.clean(car, keys(c), )– InverseFalcon
Nov 21 at 9:49
Yes. If you want to remove all existing keys from the map (so that the update operation only adds new properties and doesn't overwrite existing properties) you can supply the keys on that node as the keys to remove from the map:
SET c += apoc.map.clean(car, keys(c), )– InverseFalcon
Nov 21 at 9:49
I will test these
– MichaelE
Nov 21 at 22:01
I will test these
– MichaelE
Nov 21 at 22:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397349%2fcan-i-set-a-map-in-neo4j-cypher-without-overwriting-existing-properties%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Of Interest: Mutate specific properties using a map and +=
– Guy Coder
Nov 20 at 16:42