- This Cypher statement is valid:
MATCH (v:Vehicle)-[:OWNED_BY]->(p:Person) WITH p, collect(p.name) as owners RETURN v, owners
- Ture
- False
备注:查看With的用法
- The EXPLAIN keyword before a query shows the execution plan and what happened when the query ran (db hits).
- Ture
- False
备注:与选择题2相似,Explain和Profile都是查看执行计划,Explain只查看计划,不运行语句,Profile会运行语句
- Adding a label to a node will automatically index the name property.
- True
- False
备注:当将标签添加到节点时,会自动为节点编制索引,但只有在向属性显式添加索引或约束时,才会为属性编制索引。
- ORDER BY is a valid Cypher clause.
- True
- False
The four building blocks of a Neo4j Graph Database are:
- Nodes
- Relastionships
- Properties
- Labels
- Ture
- False
- The following Cypher statement queries the graph for employees of the Acme company.
MATCH (a:Employee {id:5})-[:WORKS_FOR]->(b:Company {name:"Acme"}) RETURN a LIMIT 10
Select the statement(s) below that describe why this statement may not return the list of all names of employees who work for Acme. Choose all that apply.
- We are matching on a node with an Employee label and with an id property of value 5, which may refer only to a single employee and not all of them.
- We are returning the nodes represented by the variable a; to get the list of employee names we would have to return a.name.
- The LIMIT 10 following the RETURN clause means we will only get 10 results and there may be more than 10 employees who work at Acme in the graph.
- The LIST keyword needs to be used in the RETURN statement to generate the list of all nodes.
备注:为什么没有返回公司所有员工的列表,1、3肯定是对的,limit和id=5的限制,4是返回的list,2满足
- The Cypher PROFILE keyword can be used for what purpose?
- The PROFILE clause will detail the current statistics for the server, including node counts, relationship counts, and data size.
- Entered before the statement it is used to return the query plan and execution information for a Cypher statement for performance tuning purposes.
- PROFILE will identify the schema for the current database, including labels in use, relationship types, and indexes.
- Used when creating parameterized Cypher queries, it tells the query engine to build a query plan for later use.
备注:考察Profile的用法,Explain和Profile都是查看执行计划,Explain只查看计划,不运行语句,Profile会运行语句,并查看那个运算符占了大部分的工作
- What are some ways that you can query data from a Neo4j database? Choose all that apply.
- Through the message queue service that ships with Neo4j.
- Through the JDBC driver shipped with Neo4j.
- Through the Bolt protocol available with the Neo4j instance.
- Using the Neo4j Browser Web interface that ships with Neo4j.
备注:查看Neo4j查询数据的方式:Bolt protocol + Neo4j Browser Web
- Which keyword in the RETURN clause will return only one instance of each item in a result set?
- UNIQUE
- FIRST
- DISTINCT
- SINGLE
- Here are two queries that return the same result:
//query 1 MATCH (p:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(m:Movie) RETURN m.title //query 2 MATCH (p:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(m) RETURN m.title
Which query will perform better and why?
- query 1 will perform better because we have specified the Movie label.
- query 1 will perform better because the Movie nodes are the anchor of the query.
- query 2 will perform better because a label check does not need to be done for the Movie nodes.
- query 2 will perform better because the Movie nodes are the anchor of the query.
备注:https://graphacademy.neo4j.com/courses/cypher-intermediate-queries/4-graph-traversal/01-graph-traversal/
- Select the Cypher statements below that will delete a node with an id of 3563 and all of its possibly connected relationships? Choose all that apply.
- MATCH (a:Thing {id:3563}) DETACH DELETE a
- MATCH (a:Thing {id:3563}) OPTIONAL MATCH (a)-[r]-() DELETE a, r
- MATCH (a:Thing {id:3563}) DELETE a
- MATCH (a:Thing {id:3563})-[r]-(b) DELETE a, r
- What statement best describes the CONNECT_BY clause in Cypher?
- The CONNECT_BY clause is used to join nodes when they are connected by varying relationship depths.
- The CONNECT_BY clause is a constraint that ensures only certain relationships can connect two nodes with specific labels together.
- The CONNECT_BY clause is used when constructing a graph tree structure where you want to define the nodes that a leaf node is connected to.
- CONNECT_BY is not a valid Cypher clause.
- The CONNECT_BY clause is used in Cypher to limit the pattern to only certain relationship types.
- In a Neo4j application, what is a session?Choose all that apply.
- A Session is a container for a sequence of transactions.
- A Session uses connections from a pool set up by the Driver.
- A Session is used to execute transactions against the DBMS or cluster.
- You can set the default transaction type for a session.
备注:https://graphacademy.neo4j.com/
- What protocols are valid for connecting your application to a Neo4j DBMS or cluster? Choose all that apply:
- aura://
- bolt://
- graphdb://
- neo4j://
- neo4j+s://
备注:可参照第三题,详情请看 https://neo4j.com/docs/browser-manual/current/operations/dbms-connection/
- Given a model consisting of nodes with the Person label connected by relationships with type KNOWS, select the statements below that will match on both Sarah’s friends and her friends of friends? Choose all that apply.
- MATCH (sarah:Person)-[:KNOWS]->(friend:Person) WHERE sarah.name = “Sarah” RETURN friend
- MATCH (sarah:Person)-[:KNOWS*1…2]->(friend:Person) WHERE sarah.name = “Sarah” RETURN friend
- MATCH (sarah:Person)-[:KNOWS]->(friend:Person) OPTIONAL MATCH (friend)-[:KNOWS]->(fof:Person) WHERE sarah.name = “Sarah” RETURN friend, fof
- All of these are correct.
备注:https://neo4j.com/docs/cypher-manual/current/syntax/patterns/ && https://neo4j.com/docs/cypher-manual/current/clauses/optional-match/
- Given the below MATCH clause, which of the following is the correct way to return the relationship types of all relationships bound to the variable b?
MATCH (a)-[b]->(c)
- RETURN b.type
- RETURN b
- RETURN type(b)
- None of these are correct.
备注:返回所有关系的Type
- Suppose an existing Person node has these properties set:
- name: ‘Joe’
- age: 30
What is the result of executing this Cypher statement:MATCH (p:Person) WHERE p.name = 'Joe' SET p = {name: 'Joseph', address: '100 Main Street'}
- The node now has these properties: { name: ‘Joseph’, address: ‘100 Main Street’}
- The node now has these properties: { name: ‘Joseph’, age: 30, address: ‘100 Main Street’}
- The node now has these properties: { name: ‘Joe’, address: ‘100 Main Street’}
- The node now has these properties: { name: ‘Joe’, age: 30, address: ‘100 Main Street’}
备注: = 和 += 的区别,=的set是整个node 所有属性直接覆盖,+=是更新操作,没有的属性默认保留原值,详情请看 https://neo4j.com/docs/cypher-manual/current/syntax/operators/
- What Neo4j site contains graph data models that you can read about and adapt for your needs?
- graphdesigns
- graphmodels
- usecases
- graphgists
备注:Neo4j hosts a site that contains example graphs (data models) that have been designed by Neo4j engineers and Neo4j Community members. You can browse the graphgists by use case or industry. You can also use a graphgist as a starting point for your application’s graph.
https://graphacademy.neo4j.com/courses/neo4j-fundamentals/1-graph-thinking/4-graphs-are-everywhere/
- What statement best describes the OPTIONAL MATCH clause in Cypher?
- OPTIONAL MATCH is not a Cypher clause.
- OPTIONAL MATCH provides parameter placeholders for Cypher queries. It holds a parameterized query and then optionally matches it against the graph with the values supplied by the client.
- The OPTIONAL MATCH searches for a described pattern that may or may not exist, assigning NULL to any identifiers in the pattern that do not exist.
- The OPTIONAL MATCH clause will take a set of property values and optionally match them against all nodes in the database.
备注:查询不存在的也能用NULL表示。 https://neo4j.com/docs/cypher-manual/current/clauses/optional-match/
- Suppose you have two Person nodes in the graph with names “John Smith” and “Tom Jones”. What statements below are valid statements for creating a relationship between these two nodes? Choose all that apply.
- A
MATCH (p:Person), (p2:Person) WHERE p.name = 'John Smith' AND p2.name = 'Tom Jones ' CREATE (p)-[]->(p2)
- B
MATCH (p:Person), (p2:Person) WHERE p.name = 'John Smith' AND p2.name = 'Tom Jones ' CREATE (p)-[:FOLLOWS]-(p2)
- C
MATCH (p:Person), (p2:Person) WHERE p.name = 'John Smith' AND p2.name = 'Tom Jones ' CREATE (p)<-[:FOLLOWS]-(p2)
- D
MATCH (p:Person), (p2:Person) WHERE p.name = 'John Smith' AND p2.name = 'Tom Jones ' CREATE (p)-[:FOLLOWS]->(p2)
备注:关系的两个必要元素:direction + type
- In Neo4j Browser, what statement do you execute to display the constraints defined for the database?
- SHOW CONSTRAINTS
- :showConstraints
- CALL db.constraints() RETURN constraints
- CALL db.schema() RETURN constraints
备注:这题感觉有问题,所有命令都无法执行成功,https://newsn.net/say/neo4j-schema.html
- What statement best describes a relationship in Neo4j?
- A link that indicates how one type of node is, or should be connected to another type of node.
- A structure with a name and direction that describes the relationship between two nodes and provides structure and context to the graph.
- The link between two types of nodes.
- A key/value pair that identifies additional nodes that a single node is related to, including direction and weight.
备注:relationship的理解
- What function allows you to create a list of values as result of an aggregation?
- collect()
- values()
- toList()
- aggregate()
备注:https://neo4j.com/docs/cypher-manual/current/syntax/lists/
toList()没有这个Function
- Property values can be the following:
- Nested Documents
- Strings
- [list of strings]
- Date
- byte[]
- [List of numbers]
- boolean values
- Numbers
备注:https://neo4j.com/docs/cypher-manual/current/syntax/values/
- In your use cases for your application, what words are typically used to define the relationships in the graph?
- nouns
- proper nouns
- verbs
- adjectives
备注:Relationships are typically verbs.
See: https://graphacademy.neo4j.com/courses/neo4j-fundamentals/1-graph-thinking/2-graph-elements/
- Which of these statements about subqueries are true? Choose all that apply.
- Subqueries can be used for post union processing.
- Subqueries can be used as expressions.
- Subqueries can overrride existing identifiers.
- Subqueries can change cardinality of a query.
备注:https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/
- In the Neo4j Data Importer App, you can save your mapping for reuse. What format is used to save the model?
- CSV
- XML
- keyValueList
- JSON
备注:https://graphacademy.neo4j.com/courses/importing-data/2-using-data-importer/1-overview/
- Suppose you want to retrieve all Person nodes that have a firstName value that starts with the string “Jo”. How would you retrieve these nodes?
- MATCH (p:Person) WHERE begins(p.firstName,2) = “Jo” RETURN p
- MATCH (p:Person) WHERE p.firstName STARTS WITH “Jo” RETURN p
- MATCH (p:Person) WHERE index(p.firstName,1,2) = “Jo” RETURN p
- MATCH (p:Person) WHERE p.firstName BEGINS WITH “Jo” RETURN p
备注:https://neo4j.com/docs/cypher-manual/current/syntax/operators/#syntax-using-starts-with-to-filter-names
- How do you perform an aggregation in Cypher?
- Using at least one aggregation function.
- Using the GROUP BY keyword.
- Defining grouping keys with WITH.
- With the AGGREGATE keyword.
- Given this Cypher query where a Movie node contains a property, languages which is a list of languages for that movie:
MATCH (m:Movie) UNWIND m.languages AS language RETURN m.title, language
What does this query return?
- A single row that contains a list of movie titles in the graph and a list of languages for all movies in the graph.
One row for every movie in the graph where each row will contain the title of the movie and a list of languages for that movie.- One row for every language in the graph where each row will contain the language and a list of movies for that language.
- One row for every movie in the graph where each row will contain the title of the movie and the language. There may be multiple rows for a movie it that movie has more than one languages element.
备注: https://neo4j.com/docs/cypher-manual/current/clauses/unwind/
- What statement best describes Cypher, Neo4j’s graph query language?
- It is a procedural programming language for interfacing with Neo4j.
- It is a regular expression-like programming language for interfacing with Neo4j.
- It is a declarative query language designed for graph pattern matching and traversals.
- It’s a SQL plugin for Neo4j.
- What Cypher statement returns the total population in all cities located in California?
- A
MATCH (city:CITY) sum(city.population) as total WHERE (city)-[:LOCATED_IN]->(:STATE {name="California"}) RETURN total
- B
MATCH (state:STATE {name:"California"}) MATCH (city:CITY) JOIN state,city RETURN SUM(city.population)
- C
SUM (:CITY.population) WHERE city.relationships(:STATE.name="California") RETURN
- D
MATCH (:STATE {name:"California"})<-[:LOCATED_IN]-(city:CITY) RETURN sum(city.population)
- Suppose we want to return the list all movies for each actor whose name contains “Tom”.
What is wrong with this code? Select the correct answer,MATCH (a:Person) WHERE a.name CONTAINS "Tom" WITH a, a.name AS actorName CALL { MATCH (a)-[:ACTED_IN]->(m:Movie) RETURN collect(m.title) as movies } RETURN actorName , movies
you must add WITH movies, actorName after the CALL{} block.- You can only pass property values to a subquery, not nodes.
- You must specify WITH in the subquery for any variables you are passing in to the subquery. In this case a.
- The WITH clause before the CALL{} block must be removed
备注:https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/
- Select the Cypher statements that will return the number of cities in the state of California. Choose all that apply.
AMATCH (state:State {name:"California"}) JOIN state, MATCH (city:City) RETURN count(city)
- B
MATCH (:State {name:"California"})<-[:LOCATED_IN]-(city:City) RETURN count(city)
- C
MATCH (city:City) FILTER relationships(LOCATED_IN) FILTER related(:STATE {name:"California"}) RETURN count(city)
- D
MATCH (state:State)<-[:LOCATED_IN]-(city:City) WHERE state.name="California" RETURN count(city)
- Which of the following options are required when using the Neo4j Data Importer App? Choose all that apply.
- The data to import must be CSV files.
You must connect to the running RDBMS and Neo4j Server to perform the import.- IDs for nodes that will be created must be unique.
- The CSV files must have a header row.
备注:https://graphacademy.neo4j.com/courses/importing-data/2-using-data-importer/1-overview/
- What Cypher keyword is used to define an alias in a Cypher statement?
- SET
- AS
- ALIAS
- USE
- How many nodes can a single relationship connect?
- Exactly two
- Exactly one
- one or two
- more than two
None of above备注:A node can have a relationship referencing itself or another node.
- Neo4j uses the property graph model. What statement best describes a property graph?
- The property graph is a model similar to RDF which describes how Neo4j stores resources in the database.
- Nodes and relationships define the graph while properties add context by storing relevant information in the nodes and relationships.
The property graph allows for configuration properties to define schema and structure of the graph.- Property graph defines a graph meta-structure that acts as a model or schema for the data as it is entered.
- What statement best describes Cypher’s MERGE clause?
- MERGE can be used to join two graph databases together by de-duplicating nodes and relationships.
- MERGE is not a valid Cypher clause.
- The MERGE clause ensures that a pattern exists in the graph. Either the pattern already exists, or it is created.
- MERGE is used to return multiple nodes in a Cypher return statement.
MERGE is used to merge multiple nodes or relationships in the graph together to form a single node or relationship.备注:https://neo4j.com/docs/cypher-manual/current/clauses/merge/
- What Cypher statement returns the keys used for properties on nodes and relationships in the database?
- RETURN db.keys()
- CALL db.keys()
- RETURN db.propertyKeys()
- CALL db.propertyKeys()
- What is the correct syntax to pass identifiers to a subquery?
- CALL (a,b,c) { }
- CALL { WITH a,b,c }
- CALL { USE a,b,c }
- CALL { … JUST USE a,b,c }
备注:https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/
- What are some options for loading data into Neo4j? Choose all that apply.
- Use the Neo4j Data Importer App.
- Execute IMPORT statements in Cypher.
- Use import procedures in the APOC library.
- Execute LOAD CSV statements in Cypher.
备注:https://graphacademy.neo4j.com/courses/importing-data/1-preparing/1-overiew/
- How do you ensure that the same relationship is not created twice between two nodes?
- Use the MERGE keyword when creating the relationship.
- Use the ONLY keyword when creating the relationship.
- Use the UNIQUE keyword when creating the relationship.
Use the DISTINCT keyword when creating the relationship.
- Suppose you want to parameterize this query:
MATCH (p:Person) WHERE p.name = XXXX
and XXXX is the parameter. You have defined a parameter called actorName that you can set in your session. How do you specify the actorName parameter in this query?
- MATCH (p:Person) WHERE p.name = #actorName
MATCH (p:Person) WHERE p.name = param(actorName)- MATCH (p:Person) WHERE p.name = $actorName
- MATCH (p:Person) WHERE p.name = value(actorName)
备注:https://neo4j.com/docs/cypher-manual/current/syntax/parameters/
- What Cypher statement will return actors and the directors who directed their movies?
- A
MATCH (actor)-[a:ACTED_IN]->(movie)<-[b:DIRECTED]-(director) RETURN a, b
- B
MATCH (actor)-[:ACTED_IN]->(movie)<-[:DIRECTED]-(director) RETURN actor, director
CMATCH (actor)-[:ACTED_IN]-(movie) CONNECT (movie)-[d:DIRECTED]-(director) RETURN actor, director
- D
MATCH (actor)-[:ACTED_IN]->(movie) JOIN (movie)<-[:DIRECTED]-(director) RETURN actor, director
- How do you define “;” as field terminator in LOAD CSV?
- LOAD CSV FROM “url” AS row WITH split(row, “;”) as fields
- LOAD CSV DELIMETER “;” FROM “url” AS row
- LOAD CSV FROM “url” AS row TERMINATED BY “;”
- LOAD CSV FROM “url” AS row FIELDTERMINATOR “;”
- Suppose you want to load a very large CSV file with Cypher. In Neo4j Browser, what clause can you use?
- USING PERIODIC COMMIT LOAD CSV…
- :auto LOAD CSV …
:LOAD CSV …- :auto USING PERIODIC COMMIT LOAD CSV. …
备注:https://graphacademy.neo4j.com/courses/importing-data/4-importing-data-cypher/1-cypher-large-files/
- What statements describe using a Neo4j Driver in your application?
Choose all that apply.
- You create a single Driver instance in your application for connecting to a Neo4j DBMS or cluster.
- Your application must use the Driver instance to access the Neo4j DBMS or cluster.
- A Neo4j Driver is thread-safe.
- Each interaction with the Neo4j DBMS or cluster requires a new Driver instance in your application.
备注:https://graphacademy.neo4j.com/
- Given this Cypher query;
MATCH (p:Person)-[r:ACTED_IN]->(m:Movie)
WHERE ‘Neo’ IN r.roles AND m.title=‘The Matrix’
RETURN p.name, r.roles
What type of data is r.roles stored as in the graph?
List- StringList
- Array
- StringArray
- Suppose you have a graph that has millions of Person nodes that are related using the :FOLLOWS relationship. Given this MATCH clause:
MATCH (follower:Person)-[:FOLLOWS*2]->(p:Person) WHERE follower.name = 'John Smith' RETURN p
What node or nodes are returned?
All Person nodes that have exactly two relationships from John Smith- All Person nodes that are one or two hops away from John Smith using the :FOLLOWS relationship.
- Two Person nodes that are followed by John Smith
- All Person nodes that are exactly two hops away from John Smith using the :FOLLOWS relationship.