简体   繁体   English

在NDB中查询PickleProperty

[英]Querying a PickleProperty in NDB

I am trying to code a Twitter-like microblogging application. 我正在尝试编写类似Twitter的微博应用程序。 In order to do that I'm using Google App Engine and the Datatstore. 为此,我使用了Google App Engine和Datatstore。

I have two classes. 我有两节课。 The Tweet class which is the parent : 作为父类的Tweet类:

class Tweet(EndpointsModel):

  _message_fields_schema = ('sender','body', 'name')

  sender = ndb.StringProperty()
  body = ndb.TextProperty()
  created = ndb.DateTimeProperty(auto_now=True)
  ...

And the TweetIndex class, which is the child that contains all the receivers for a tweet. 还有TweetIndex类,它是包含所有tweet接收者的子级。

class TweetIndex(EndpointsModel):
  ...
  receivers = ndb.PickleProperty(indexed=True,repeated=True)
  created = ndb.DateTimeProperty(auto_now=True)
  ...

@TweetIndex.method(request_fields=('receivers',),
                    path='mymodels', name='mymodel.list')
def MyModelList(self, query):
if not query.from_datastore:
    raise endpoints.NotFoundException('MyModel not found.')
return query

I'm trying to query the TweetIndex entities with the API method MyModelList which purpose is to return the TweetIndex entity if a given id is included in the receivers array. 我正在尝试使用API​​方法MyModelList查询TweetIndex实体,目的是如果接收方数组中包含给定的ID,则返回TweetIndex实体。

Example of a receivers array : 接收方数组的示例:

 ["13911772075915175317","1855429131779793831", ... ]

Which looks something like this in the datastore (stored as a blob): 在数据存储区(存储为Blob)中看起来像这样:

["gAJYEwAAADY1NjU2NDM3MzA1NDI2NDU5ODlxAS4=","gAJYEwAAADU4MDM3MjE4OTEyNDgzNzgyNjNxAS4=",...]

However, when executing the following API request: 但是,在执行以下API请求时:

POST https://myapi/.../v1/mymodels

{
 "receivers": [
  "13911772075915175317"
 ]
}

The following is returned: 返回以下内容:

404

- Show headers -

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "MyModel not found."
   }
  ],
  "code": 404,
  "message": "MyModel not found."
 }
}

"13911772075915175317" does exist at least once in a receivers array. “ 13911772075915175317”在接收器数组中至少存在一次。 I also tried to input the blobs in the request (but with no surprise) did not work either. 我也尝试在请求中输入Blob(但不足为奇)也不起作用。

How am I supposed to query this array correctly? 我应该如何正确查询该数组?

You'll need to query your receivers array with the pickled version. 您需要用腌制版查询接收器数组。 Given that a PickledProperty is binary data, it won't be easy to query. 由于PickledProperty是二进制数据,因此查询起来并不容易。 You are probably better off changing from PickledProperty to whatever type you actually want, in this case IntegerProperty. 从PickledProperty更改为实际所需的任何类型(在这种情况下为IntegerProperty),可能更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM