Reputation: 1581
Neo4j Bulk Insert is getting the same UUID value / getting the same return value.
/**
* @method createAlbumAndTracks
* @param album
* @param tracks
* @returns {any}
*/
createAlbumAndTracks(album:any, tracks:any[]):any {
const query = `
UNWIND {trackList} as track
MERGE (a:Albums ${insertQuery(album)})
CREATE (t:Tracks)
SET
t = track,
t.id = '${uuid()}', // unique UUID expected
t.created = timestamp()
MERGE (a)-[r:ALBUM_TRACKS]->(t)
RETURN t`;
return db.run(query, Object.assign(album, {trackList: tracks}));
}
t.id = '${uuid()}' is getting the same value though it should be an unique UUID. How to invoke the function each time a new node is created?
Upvotes: 4
Views: 464
Reputation: 41706
Because you only create the query once but then you create one track per array item.
You should add the uuids to your tracklist (as objects)
tracklist = [{track:"Track", uuid:uuid()},....]
and then use track.track
and track.uuid
in your query.
Upvotes: 4