Accessing Node Properties
Select the correct method to access the name
property from a node.
node, _ := record.Get("person")
personNode := node.(neo4j.Node)
name, exists := personNode./*select:Props["name"]*/
if !exists {
name = "Unknown"
}
-
❏ Get("name")
-
✓ Props["name"]
-
❏ ValueOf("name")
-
❏ properties["name"]
Hint
The Props
map returns the value and a boolean indicating if the property exists, similar to Go’s map access pattern.
Solution
The correct answer is Props["name"]
. This method allows you to safely access a node property and check if it exists.
name, exists := personNode.Props["name"]
if !exists {
name = "Unknown"
}
The Props
map access returns both the value and a boolean indicating whether the property exists, which follows the Go idiom for safe map access.
Accessing Relationship Type
Select the correct property to access the type of the acted_in
relationship.
relationship, _ := record.Get("acted_in")
relObj := relationship.(neo4j.Relationship)
relType := relObj./*select:Type*/
fmt.Printf("Type: %s", relType) // prints: Type: ACTED_IN
-
❏ Name
-
❏ RelationshipType
-
✓ Type
-
❏ Label
Hint
The relationship type (e.g., ACTED_IN
) is accessed through a simple property on the relationship object.
Solution
The correct answer is Type
. This property returns the type of the relationship as a string.
relationship, _ := record.Get("acted_in")
relObj := relationship.(neo4j.Relationship)
relType := relObj.Type // returns: "ACTED_IN"
The Type
property is the standard way to access the relationship type in Neo4j’s Go driver.
Lesson Summary
In this lesson, you correctly identified how to access properties from nodes and the type of a relationships.
In the next lesson, you will learn how to work with dates and times.