Search code examples
javascriptdatabaseobjectparse-platformparse-server

Is there a way to make the queries on the Parse Server shorter?


Original Query

const Post = Parse.Object.extend('Post')
const queryPost = new Post()

queryPost.startsWith('title', 'Good Programming')
queryPost.greaterThan('totalLike', 1000)
queryPost.limit(100)
queryPost.include('author')

query.find()

Expected Query

const Post = Parse.Object.extend('Post')
const queryPost = new Post()

queryPost.find({
   startsWith: {
      title: 'Good Programming'
   },
   greaterThan: {
      totalLike: 1000
   },
   include: ['post'],
   limit: 100
})

The advantage of the method above, I can do the copy and paste as usual when I want to do trials across places.


Solution

  • You can do something like the following but it is not documented:

    const query = Parse.Query.fromJSON('ClassName', {
      where: {
        title: {
          '$regex': '^Good Programming'
        },
        totalLike: {
          '$gt': 1000
        }
      },
      include: 'post',
      limit: 100
    });
    
    query.find();