0

I have following structure of entities(table)

class MovieStatus(ndb.Model): 
     movie_name = ndb.TextProperty()
     preference = ndb.IntergerPropety()  

and my entries are like below,

movie_name  |  preference
Highway             3
Highway             1   
Queen               1
Queen               1  
Highway             2
Queen               2
Queen               1

I want to get Movie name having max number of 1's as preference

In Above case Queen is appeared max times(3 times) with preference 1 so my expected answer is Queen? any Idea for such query?

I am currently able to sort it using

MovieStatus.query().order(MovieStatus.preference, MovieStatus.movie_name)

movie_name  |  preference
Highway             1   
Queen               1
Queen               1
Queen               1
Highway             2
Queen               2
Highway             3

Also I was trying to search group by syntax but for datastore I could not find it.

Nikhil Rupanawar
  • 4,061
  • 10
  • 35
  • 51

1 Answers1

0

You already have your answer. There is no "SQL like" features, all you can do with the datastore is query for entities with basic criterias, and process your results programmatically... like you just did.

The only thing you can do differently is creating additional entities dedicated to counting for each movie, and updating them as you create new "MovieStatus" entities.

Michael Técourt
  • 3,457
  • 1
  • 28
  • 45