Big Data & Tools with NoSQL
  • Big Data & Tools
  • ReadMe
  • Big Data Overview
    • Overview
    • Job Opportunities
    • What is Data?
    • How does it help?
    • Types of Data
    • The Big 4 V's
      • Variety
      • Volume
      • Velocity
      • Veracity
      • Other V's
    • Trending Technologies
    • Big Data Concerns
    • Big Data Challenges
    • Data Integration
    • Scaling
      • CAP Theorem
      • Optimistic concurrency
      • Eventual consistency
      • Concurrent vs. Parallel Programming
    • Big Data Tools
    • No SQL Databases
    • What does Big Data learning means?
  • Linux & Tools
    • Overview
    • Linux Commands - 01
    • Linux Commands - 02
    • AWK
    • CSVKIT
    • CSVSQL
    • CSVGREP
  • Data Format
    • Storage Formats
    • CSV/TSV/Parquet
    • Parquet Example
    • JSON
    • HTTP & REST API
      • Terms to Know
        • Statefulness
        • Statelessness
        • Monolithic Architecture
        • Microservices
        • Idempotency
    • REST API
    • Python
      • Setup
      • Decorator
      • Unit Testing
      • Flask Demo
      • Flask Demo - 01
      • Flask Demo - 02
      • Flask Demo - 03
      • Flask Demo - 04
      • Flask Demo - 06
    • API Testing
    • Flask Demo Testing
    • API Performance
    • API in Big Data World
  • NoSQL
    • Types of NoSQL Databases
    • Redis
      • Overview
      • Terms to know
      • Redis - (RDBMS) MySql
      • Redis Cache Demo
      • Use Cases
      • Data Structures
        • Strings
        • List
        • Set
        • Hash
        • Geospatial Index
        • Pub/Sub
        • Redis - Python
      • Redis JSON
      • Redis Search
      • Persistence
      • Databases
      • Timeseries
    • Neo4J
      • Introduction
      • Neo4J Terms
      • Software
      • Neo4J Components
      • Hello World
      • Examples
        • MySQL: Neo4J
        • Sample Transactions
        • Sample
        • Create Nodes
        • Update Nodes
        • Relation
        • Putting it all together
        • Commonly used Functions
        • Data Profiling
        • Queries
        • Python Scripts
      • More reading
    • MongoDB
      • Sample JSON
      • Introduction
      • Software
      • MongoDB Best Practices
      • MongoDB Commands
      • Insert Document
      • Querying MongoDB
      • Update & Remove
      • Import
      • Logical Operators
      • Data Types
      • Operators
      • Aggregation Pipeline
      • Further Reading
      • Fun Task
        • Sample
    • InfluxDB
      • Data Format
      • Scripts
  • Python
    • Python Classes
    • Serialization-Deserialization
  • Tools
    • JQ
    • DUCK DB
    • CICD Intro
    • CICD Tools
      • CI YAML
      • CD Yaml
    • Containers
      • VMs or Containers
      • What container does
      • Podman
      • Podman Examples
  • Cloud Everywhere
    • Overview
    • Types of Cloud Services
    • Challenges of Cloud Computing
    • High Availability
    • Azure Cloud
      • Services
      • Storages
      • Demo
    • Terraform
  • Data Engineering
    • Batch vs Streaming
    • Kafka
      • Introduction
      • Kafka Use Cases
      • Kafka Software
      • Python Scripts
      • Different types of Streaming
    • Quality & Governance
    • Medallion Architecture
    • Data Engineering Model
    • Data Mesh
  • Industry Trends
    • Roadmap - Data Engineer
    • Good Reads
      • IP & SUBNET
Powered by GitBook
On this page
  1. NoSQL
  2. Neo4J
  3. Examples

Sample Transactions

// Create sample nodes
CREATE (rachel:Customer {name: 'Rachel'})
CREATE (ross:Customer {name: 'Ross'})
CREATE (monica:Customer {name: 'Monica'})
CREATE (chandler:Customer {name: 'Chandler'})
CREATE (joey:Customer {name: 'Joey'})
CREATE (phoebe:Customer {name: 'Phoebe'})
CREATE (card1:CreditCard {number: '1234567890123456'})
CREATE (card2:CreditCard {number: '9876543210987654'})
CREATE (card3:CreditCard {number: '2345678901234567'})
CREATE (card4:CreditCard {number: '7890123456789012'})
CREATE (card5:CreditCard {number: '3456789012345678'})
CREATE (card6:CreditCard {number: '6789012345678901'})
CREATE (macys:Merchant {name: 'Macys'})
CREATE (officeDepot:Merchant {name: 'Office Depot'})
CREATE (centralPerk:Merchant {name: 'Central Perk'})
CREATE (pizzaHut:Merchant {name: 'Pizza Hut'})
CREATE (bloomingdales:Merchant {name: 'Bloomingdales'})
// Create relationships
CREATE (rachel)-[:OWNS]->(card1)
CREATE (ross)-[:OWNS]->(card2)
CREATE (monica)-[:OWNS]->(card3)
CREATE (chandler)-[:OWNS]->(card4)
CREATE (joey)-[:OWNS]->(card5)
CREATE (phoebe)-[:OWNS]->(card6)
// Create sample transactions
CREATE (tx1:Transaction {amount: 100, timestamp: datetime()})
CREATE (tx2:Transaction {amount: 200, timestamp: datetime()})
CREATE (tx3:Transaction {amount: 50, timestamp: datetime()})
CREATE (tx4:Transaction {amount: 300, timestamp: datetime()})
CREATE (tx5:Transaction {amount: 75, timestamp: datetime()})
CREATE (tx6:Transaction {amount: 120, timestamp: datetime()})
CREATE (tx7:Transaction {amount: 500, timestamp: datetime()})
CREATE (tx8:Transaction {amount: 40, timestamp: datetime()})
CREATE (tx9:Transaction {amount: 250, timestamp: datetime()})
CREATE (tx10:Transaction {amount: 80, timestamp: datetime()})
CREATE (card1)-[:USED_IN]->(tx1)-[:MADE_AT]->(macys)
CREATE (card1)-[:USED_IN]->(tx2)-[:MADE_AT]->(officeDepot)
CREATE (card2)-[:USED_IN]->(tx3)-[:MADE_AT]->(macys)
CREATE (card2)-[:USED_IN]->(tx4)-[:MADE_AT]->(officeDepot)
CREATE (card3)-[:USED_IN]->(tx5)-[:MADE_AT]->(centralPerk)
CREATE (card3)-[:USED_IN]->(tx6)-[:MADE_AT]->(bloomingdales)
CREATE (card4)-[:USED_IN]->(tx7)-[:MADE_AT]->(macys)
CREATE (card5)-[:USED_IN]->(tx8)-[:MADE_AT]->(pizzaHut)
CREATE (card5)-[:USED_IN]->(tx9)-[:MADE_AT]->(macys)
CREATE (card6)-[:USED_IN]->(tx10)-[:MADE_AT]->(centralPerk)

Find all customers

MATCH (c:Customer)
RETURN c.name

Find all transactions made at Macys

MATCH (tx:Transaction)-[:MADE_AT]->(m:Merchant)
WHERE m.name = 'Macys'
RETURN tx.amount, tx.timestamp

Find all credit cards owned by Ross

MATCH (ross:Customer {name: 'Ross'})-[:OWNS]->(card:CreditCard)
RETURN card.number

Find the customer who made a specific transaction for 120

MATCH (c:Customer)-[:OWNS]->(card:CreditCard)-[:USED_IN]->(tx:Transaction)
WHERE tx.amount = 120 
RETURN c.name

Find the merchants where Monica made transactions

MATCH (monica:Customer {name: 'Monica'})-[:OWNS]->(card:CreditCard)-[:USED_IN]->(tx:Transaction)-[:MADE_AT]->(m:Merchant)
RETURN DISTINCT m.name

Find the total amount spent by Chandler at Macys

MATCH (chandler:Customer {name: 'Chandler'})-[:OWNS]->(card:CreditCard)-[:USED_IN]->(tx:Transaction)-[:MADE_AT]->(macys:Merchant {name: 'Macys'})
RETURN SUM(tx.amount) AS total_spent
PreviousMySQL: Neo4JNextSample

Last updated 1 year ago