Reputation: 567
Given a datastore entity structure where one column (dates) contains an object array:
[{date: 2018-01-01T00:00:00Z, otherProps:x }, {date: 2018-01-02T00:00:00Z, otherProps: x}, {date: 2017-12-31T00:00:00Z, otherProps: x}]
Is it possible to construct a complex index and a query on the earliest date within the entities dates array.
For example, I would like to select all entities where the earliest date is before a certain date... This is my first foray into NoSQL so apologies if this is obvious!
Upvotes: 0
Views: 2057
Reputation: 629
You can reference to a element in a query by simple using arrayName.date < certainDate
. It will work because the index is not composite, it means you are not trying to filter something like yourKind.property = value and arrayName.date < certainDate
.
I strongly recommend you not to save date as string but instead using a timestamp (like javascript (new Date()).getTime()), it will make it very much easier in the long therm, mainly if you are using more than one timezone.
Upvotes: 0
Reputation: 39824
That may be tricky because query ordering and filtering are, in general, based on the property values and in your case the values would be the entire date arrays, not just the date values inside them.
Depending on the actual client library you use it might be possible. See, for example, Structured Properties and Filtering for Structured Property Values available with the ndb
client library.
Personally I'd rather create separate entities for each of these date arrays, with the date
and otherProps
as properties - much simpler to use as sort/filter in queries. And in general a more scalable approach, IMHO, since it avoids the lists of (repeated) date array properties, see Creating your own activity logging in GAE/P.
Upvotes: 1