salyela
salyela

Reputation: 1655

Key-based query in Cloud NDB

I’m guessing this is very simple, but I’m having a hard time getting it right. I successfully created multiple Entities of the type

class Word(ndb.Model):
    name = ndb.StringProperty(required=True)
    definition = ndb.StringProperty(required=True)

Now I want to query for a specific Entity in the most efficient way possible. So I am doing

with client.context():
  ans = Word.query(ndb.Key(“Word”,”love”)).get()

But I get an error

File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/ndb/query.py", line 1531, in filter
    "Cannot filter a non-Node argument; received %r" % filter
TypeError: Cannot filter a non-Node argument; received Key(‘Word’, ‘love’)” 

I look in my datastore and the word is there. How do I do this successfully?

Upvotes: 0

Views: 49

Answers (1)

salyela
salyela

Reputation: 1655

It turns out all I had to do was

with client.context():
  ans = ndb.Key(“Word”,”love”).get()

Upvotes: 1

Related Questions