Giter VIP home page Giter VIP logo

integreat-transporter-mongodb's People

Contributors

dependabot-preview[bot] avatar kjellmorten avatar

Watchers

 avatar

integreat-transporter-mongodb's Issues

Sort returned results from GET requests

Sorting should be specified by setting a sort object on an endpoint.

Example endpoint:

{
  scope: 'collection',
  type: 'entry',
  sort: {
    'attributes.updatedAt': -1
  }
}

The sort object will be passed directly to MongoDB's sort() method as is.

Return number of items

This is easy when fetching one page. With multiple pages, the total number of items will probably have to be fetched in a separate query.

Return query for next page

When a GET request contains a pageSize param, paging kicks in, and the response should contain a paging object with params for getting the next page of results. The param object should be included with the params in the request for the next page.

For example, the action ...

{type: 'GET', payload: {type: 'entry', pageSize: 20}}

... will return a response looking like this:

{
  status: 'ok',
  data: [...],
  paging: {
    next: {
      query: {_id: {$gte: 'ent19'}},
      pageAfter: 'ent19',
      pageSize: 20
  }
}

What the adapter will do on this request, is stepping through the results until it reaches the document with id: 'ent19' (from the pageAfterprop), and return the next 20 items after that one. To make this a bit more efficient, the query object is added to the query from endpoint, so in this case, the pageAfter id will always be the first in the result set.

When the endpoint has a sort object, the sorting props will be use to build the query object for the next page, so that the pageAfter id will be included in the result, but not be further down than necessary.

For example, with descending sorting on attributes.updatedAt, the result will look like this:

{
  status: 'ok',
  data: [...],
  paging: {
    next: {
      query: {'attributes.updated': {$lte: new Date(...)}},
      pageAfter: 'ent19',
      pageSize: 20
    }
  }
}

As the sorting is ascending, by getting every entry that has an updatedAt date earlier than that of the last document on the previous page, we're sure to get the pageAfter document and we'll know where to start returning documents for the next page.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.