1

Trying to use predicates with NodeMatcher()... am I doing something wrong here?

In [24]: nodes = NodeMatcher(neodb)

In [25]: nodes.match("Interface", ipv4=STARTS_WITH("192.168.240.170")).first()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-25-22cdc9c394bd> in <module>
----> 1 nodes.match("Interface", ipv4=STARTS_WITH("192.168.240.170")).first()

NameError: name 'STARTS_WITH' is not defined
chomezki
  • 11
  • 1

2 Answers2

0

The syntax is incorrect. Please refer to this documentation: https://py2neo.org/v4/matching.html

You should suffix the property with __startswith. For example:

nodes.match("Interface", ipv4__startswith="192.168.240.170").first()
jose_bacoy
  • 12,227
  • 1
  • 20
  • 38
  • no thats not correct the updated version supports the above syntax: https://py2neo.org/2021.1/matching.html#applying-predicates – chomezki Nov 24 '21 at 03:32
0

The solution is I needed to import the predicate class:

In [13]: from py2neo.matching import STARTS_WITH
In [14]: nodes.match("Interface", ipv4=STARTS_WITH("192.168")).first()
Out[14]: Node('Interface', admin=True, description='inside', hostUUID='asa-core', ipv4='192.168.199.11/27', name='GigabitEthernet0/0', operational=True)
chomezki
  • 11
  • 1