我试图将新4j瓶应用程序更新为Py2Neo V4,但找不到"find_one“函数是如何被替换的。(妮可怀特使用Py2Neo V2)
我的设置:
Requirements.txt (其余代码来自Nicole White的github存储库):
atomicwrites==1.2.0
attrs==18.1.0
backcall==0.1.0
bcrypt==3.1.4
certifi==2018.8.24
cffi==1.11.5
click==6.7
colorama==0.3.9
decorator==4.3.0
Flask==1.0.2
ipykernel==4.8.2
ipython==6.5.0
ipython-genutils==0.2.0
itsdangerous==0.24
jedi==0.12.1
Jinja2==2.10
jupyter-client==5.2.3
jupyter-console==5.2.0
jupyter-core==4.4.0
MarkupSafe==1.0
more-itertools==4.3.0
neo4j-driver==1.6.1
neotime==1.0.0
parso==0.3.1
passlib==1.7.1
pexpect==4.6.0
pickleshare==0.7.4
pkg-resources==0.0.0
pluggy==0.7.1
prompt-toolkit==1.0.15
ptyprocess==0.6.0
py==1.6.0
py2neo==4.1.0
pycparser==2.18
Pygments==2.2.0
pytest==3.7.3
python-dateutil==2.7.3
pytz==2018.5
pyzmq==17.1.2
simplegeneric==0.8.1
six==1.11.0
tornado==5.1
traitlets==4.3.2
urllib3==1.22
wcwidth==0.1.7
Werkzeug==0.14.1注册用户时收到的错误:
AttributeError:图形对象没有属性'find_one‘ “User.find()方法使用py2neo的Graph.find_one()方法在数据库中查找带有label :User和给定用户名的节点,并返回py2neo.Node对象。”
在Py2Neo V3中,函数find_one -> one是可用的。
在Py2Neo V4 https://py2neo.org/v4/matching.html中,不再存在查找函数。
有人对如何在V4中解决这个问题有了一个想法,或者说在这里被降级是可行的吗?
发布于 2018-08-28 13:00:10
py2neo v4有一个first函数,可以与NodeMatcher一起使用。请参阅:https://py2neo.org/v4/matching.html#py2neo.matching.NodeMatch.first
上面说..。v4引入了GraphObjects (至少到目前为止),我发现它相当整洁。
在链接的github示例中,创建用户时:
user = Node('User', username=self.username, password=bcrypt.encrypt(password))
graph.create(user)被发现时
user = graph.find_one('User', 'username', self.username)在py2neo v4中,我会用
class User(GraphObject):
__primarykey__ = "username"
username = Property()
password = Property()
lukas = User()
lukas.username = "lukasott"
lukas.password = bcrypt.encrypt('somepassword')
graph.push(lukas)和
user = User.match(graph, "lukasott").first()据我理解,first函数提供了同样的保证,即find_one (引用自v3文档)“如果找到多个匹配节点,就不会失败。”
发布于 2020-10-16 01:55:18
这对我起了作用。参考下面的链接
def find(self):
user = graph.nodes.match("User", self.username).first()
return user发布于 2020-11-24 19:11:19
解决这一问题的另一种更简单的方法是将find_one替换为以下内容:
from py2neo import Graph, NodeMatcher
matcher = NodeMatcher(graph)
user = matcher.match('user', name='name').first()https://stackoverflow.com/questions/52056004
复制相似问题