|
| 1 | += apoc.create.virtual.fromNodeExtended |
| 2 | +:description: This section contains reference documentation for the apoc.create.virtual.fromNodeExtended function. |
| 3 | + |
| 4 | +label:function[] label:apoc-extended[] |
| 5 | + |
| 6 | +[.emphasis] |
| 7 | +apoc.create.virtual.fromNodeExtended(node, [propertyNames]) returns a virtual node built from an existing node with only the requested properties |
| 8 | + |
| 9 | +== Signature |
| 10 | + |
| 11 | +[source] |
| 12 | +---- |
| 13 | +apoc.create.virtual.fromNodeExtended(node :: NODE?, propertyNames :: LIST? OF STRING?, additionalProperties :: MAP, ?config :: MAP?) :: (NODE?) |
| 14 | +---- |
| 15 | + |
| 16 | +== Input parameters |
| 17 | +[.procedures, opts=header] |
| 18 | +|=== |
| 19 | +| Name | Type | Default |
| 20 | +|node|NODE?|null |
| 21 | +|propertyNames|LIST? OF STRING?|null |
| 22 | +|additionalProperties|MAP?|{} |
| 23 | +|config|MAP?|{} |
| 24 | +|=== |
| 25 | + |
| 26 | +[[config-apoc.create.virtual.fromNodeExtended]] |
| 27 | +== Configuration parameters |
| 28 | + |
| 29 | +The procedures support the following config parameters: |
| 30 | + |
| 31 | +.Config parameters |
| 32 | +[opts=header] |
| 33 | +|=== |
| 34 | +| name | type | default | description |
| 35 | +| wrapNodeIds | boolean | false | By default, this function will change the id of the node to a negative number which is representative of Virtual Nodes. We can set it to true in order to retain the original id. |
| 36 | +|=== |
| 37 | + |
| 38 | +[[usage-apoc.create.virtual.fromNodeExtended]] |
| 39 | +== Usage Examples |
| 40 | +The examples in this section are based on the following graph: |
| 41 | + |
| 42 | +[source,cypher] |
| 43 | +---- |
| 44 | +CREATE (a:Account {type: 'checking', ownerName: 'Maria Perez', ownerId: '123456789', accountNumber: 101010101, routingNumber: 10101010, amount: 1000.00, bank: 'Best Bank'}); |
| 45 | +CREATE (p:Person {name: 'Jane Doe', birthdate: date('1990-01-13'), favoriteColor: 'green', favoriteDessert: 'ice cream', favoriteMusic: 'classical', favoriteBand: 'The Beatles', favoriteVacation: 'beach', favoriteAnimal: 'horse', favoriteBeverage: 'coffee', favoriteFlower: 'lily'}); |
| 46 | +---- |
| 47 | + |
| 48 | +The apoc.create.virtual.fromNodeExtended procedure provides a way to only visualize or return data that is needed, hiding any unnecessary or sensitive pieces. |
| 49 | + |
| 50 | +The example below shows how we can use the procedure to return only the non-sensitive properties from the node above: |
| 51 | + |
| 52 | +// tag::tabs[] |
| 53 | +[.tabs] |
| 54 | +.apoc.create.virtual.fromNodeExtended |
| 55 | +[source,cypher] |
| 56 | +---- |
| 57 | +MATCH (a:Account {accountNumber: 101010101}) |
| 58 | +RETURN apoc.create.virtual.fromNodeExtended(a, ['type','bank']); |
| 59 | +---- |
| 60 | +// end::tabs[] |
| 61 | + |
| 62 | +.Results |
| 63 | +[opts="header"] |
| 64 | +|=== |
| 65 | +| account |
| 66 | +| {"type":"checking","bank":"Best Bank"} |
| 67 | +|=== |
| 68 | + |
| 69 | +The apoc.create.virtual.fromNodeExtended procedure can also be used to simplify nodes with many properties by only displaying ones that are important to the query. |
| 70 | + |
| 71 | +The example below shows an example of this use: |
| 72 | + |
| 73 | +.apoc.create.virtual.fromNodeExtended |
| 74 | +[source,cypher] |
| 75 | +---- |
| 76 | +MATCH (p:Person {name: 'Jane Doe'}) |
| 77 | +RETURN apoc.create.virtual.fromNodeExtended(p, ['favoriteColor','favoriteAnimal','favoriteMusic']); |
| 78 | +---- |
| 79 | + |
| 80 | +.Results |
| 81 | +[opts="header"] |
| 82 | +|=== |
| 83 | +|favorites |
| 84 | +|{"favoriteAnimal":"horse", "favoriteMusic":"classical", "favoriteColor":"green"} |
| 85 | +|=== |
| 86 | + |
| 87 | +We can also set additional properties via the 3rd parameter. |
| 88 | +The example below shows an example of this use: |
| 89 | + |
| 90 | +.apoc.create.virtual.fromNodeExtended |
| 91 | +[source,cypher] |
| 92 | +---- |
| 93 | +MATCH (p:Person {name: 'Jane Doe'}) |
| 94 | +RETURN apoc.create.virtual.fromNodeExtended(p, ['favoriteColor','favoriteAnimal','favoriteMusic'], {foo: 'bar', alpha: 1}); |
| 95 | +---- |
| 96 | + |
| 97 | +.Results |
| 98 | +[opts="header"] |
| 99 | +|=== |
| 100 | +|favorites |
| 101 | +|{"favoriteAnimal":"horse", "favoriteMusic":"classical", "favoriteColor":"green", "foo":"bar", "alpha":1} |
| 102 | +|=== |
| 103 | + |
| 104 | +[[wrapping-nodes]] |
| 105 | +=== Wrapping nodes |
| 106 | +By default, this function will change the id of the node to a negative number which is representative of Virtual Nodes. |
| 107 | +In order to retain the original id, use the config item `{ wrapNodeIds: true }`. |
| 108 | + |
| 109 | +.apoc.create.virtual.fromNodeExtended |
| 110 | +[source,cypher] |
| 111 | +---- |
| 112 | +CREATE (p:Person {name: 'Jane Doe'}) |
| 113 | +WITH apoc.create.virtual.fromNodeExtended(p, ['name'], {}, { wrapNodeIds: true }) AS node |
| 114 | +RETURN id(node) AS id; |
| 115 | +---- |
| 116 | + |
| 117 | +.Results |
| 118 | +[opts="header"] |
| 119 | +|=== |
| 120 | +| id |
| 121 | +| 1 |
| 122 | +|=== |
| 123 | + |
| 124 | + |
| 125 | +xref::virtual-resource/index.adoc[More documentation of apoc.create.virtual.fromNodeExtended,role=more information] |
0 commit comments