Bulk Relationships
Connect or disconnect many records at once by matching on property keys. Useful after importing flat data from CSV, MongoDB exports, or external APIs where related records arrive separately with reference fields.
Bulk Create by Key Match
Connect records by matching a property on the source label to a property on the target label. All pairs where the values are equal are linked.
- Python
- TypeScript
- shell
db.relationships.create_many()
# MOVIE.directorId == DIRECTOR.id → create DIRECTED_BY
db.relationships.create_many(
source={"label": "MOVIE", "key": "directorId"},
target={"label": "DIRECTOR", "key": "id"},
type="DIRECTED_BY",
direction="out"
)
# Creates: (MOVIE) -[:DIRECTED_BY]-> (DIRECTOR) where MOVIE.directorId = DIRECTOR.id
db.relationships.createMany()
await db.relationships.createMany({
source: { label: 'MOVIE', key: 'directorId' },
target: { label: 'DIRECTOR', key: 'id' },
type: 'DIRECTED_BY',
direction: 'out'
})
// Creates: MOVIE -[:DIRECTED_BY]-> DIRECTOR where MOVIE.directorId = DIRECTOR.id
POST /api/v1/relationships/create-many
curl -X POST https://api.rushdb.com/api/v1/relationships/create-many \
-H "Authorization: Bearer $RUSHDB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source": {"label": "MOVIE", "key": "directorId"},
"target": {"label": "DIRECTOR", "key": "id"},
"type": "DIRECTED_BY",
"direction": "out"
}'
Parameters
| Field | Type | Description |
|---|---|---|
source | {label, key?, where?} | Source selector — label + key for equality join, or where for filter-based match |
target | {label, key?, where?} | Target selector — same |
type | string | Relationship type to create |
direction | "in" | "out" | Direction from source to target |
manyToMany | boolean | Cartesian product mode (see below) |
Bulk Delete by Key Match
Same shape as createMany. Removes relationships where the key values match.
- Python
- TypeScript
- shell
db.relationships.delete_many(
source={"label": "MOVIE", "key": "directorId"},
target={"label": "DIRECTOR", "key": "id"},
type="DIRECTED_BY",
direction="out"
)
db.relationships.deleteMany()
await db.relationships.deleteMany({
source: { label: 'MOVIE', key: 'directorId' },
target: { label: 'DIRECTOR', key: 'id' },
type: 'DIRECTED_BY',
direction: 'out'
})
POST /api/v1/relationships/delete-many
curl -X POST https://api.rushdb.com/api/v1/relationships/delete-many \
-H "Authorization: Bearer $RUSHDB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source": {"label": "MOVIE", "key": "directorId"},
"target": {"label": "DIRECTOR", "key": "id"},
"type": "DIRECTED_BY"
}'
Many-to-Many (Cartesian)
Connect or disconnect all records matching source conditions with all records matching target conditions.
This mode creates a cartesian product — all source × all target pairs are linked. It is opt-in and requires non-empty where filters on both sides to prevent accidental unbounded operations.
- Python
- TypeScript
- shell
# Tag all sci-fi movies with all genre tags
db.relationships.create_many(
source={"label": "MOVIE", "where": {"genre": "sci-fi"}},
target={"label": "TAG", "where": {"category": "genre"}},
type="HAS_TAG",
many_to_many=True
)
Delete example:
# Remove HAS_TAG between all sci-fi movies and all genre tags
db.relationships.delete_many(
source={"label": "MOVIE", "where": {"genre": "sci-fi"}},
target={"label": "TAG", "where": {"category": "genre"}},
type="HAS_TAG",
many_to_many=True
)
// Create
await db.relationships.createMany({
source: { label: 'MOVIE', where: { genre: 'sci-fi' } },
target: { label: 'TAG', where: { category: 'genre' } },
type: 'HAS_TAG',
manyToMany: true
})
// Delete
await db.relationships.deleteMany({
source: { label: 'MOVIE', where: { genre: 'sci-fi' } },
target: { label: 'TAG', where: { category: 'genre' } },
type: 'HAS_TAG',
manyToMany: true
})
# Create
curl -X POST https://api.rushdb.com/api/v1/relationships/create-many \
-H "Authorization: Bearer $RUSHDB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source": {"label": "MOVIE", "where": {"genre": "sci-fi"}},
"target": {"label": "TAG", "where": {"category": "genre"}},
"type": "HAS_TAG",
"manyToMany": true
}'
# Delete
curl -X POST https://api.rushdb.com/api/v1/relationships/delete-many \
-H "Authorization: Bearer $RUSHDB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source": {"label": "MOVIE", "where": {"genre": "sci-fi"}},
"target": {"label": "TAG", "where": {"category": "genre"}},
"type": "HAS_TAG",
"manyToMany": true
}'
source.where and target.where must be non-empty when manyToMany: true.See also
- Connect Records — attach / detach individual record pairs
- Import Data — nested JSON auto-creates relationships on import
- Find & Query — Relationship Traversal — filter records via graph edges