Code Monkey home page Code Monkey logo

mongoose-sex-page's Introduction

mongoose-sex-page

mongoose-sex-page Build Status

🔥 a api friendly mongoose pagination tool

install

npm install --save mongoose-sex-page

usage

const Dummy = mongoose.model('Dummy', DummySchema)
const P  = require('mongoose-sex-page')
  • simple

P(Dummy)
  .page(1)
  .size(20)
  .exec()
  .then((result) => {

  })
  • complex

P(Dummy)
  .find({dummy: dummy})
  .page(1)
  .size(20)
  .display(8)
  .simple(true)
  .exec()
  .then((result) => {

  })
  • config

P().config({
  page_name: 'page',
  size_name: 'size',
  size: 20,
  display: 10,
  // only return records
  light: true
})
  • convenient

// for such a request /users?size=20&page=1 /news?size=20&page=1
P().config({
  page_name: 'page',
  size_name: 'size',
  size: 20
})
// then
P(Dummy)
  .find({dummy: dummy})
  .inject(req.query)
  .exec()
  .then((result) => {

  })

result sample

{
  "page": 1,
  "size": 5,
  "total": 100,
  "records": [{
    "name": "Test1",
    "age": 1
  }, {
    "name": "Test2",
    "age": 2
  }, {
    "name": "Test3",
    "age": 3
  }, {
    "name": "Test4",
    "age": 4
  }, {
    "name": "Test5",
    "age": 5
  }],
  "pages": 20,
  "display": [1, 2, 3, 4, 5, 6]
}

test

npm test

mongoose-sex-page's People

Contributors

barca-boy avatar dtboy1995 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mongoose-sex-page's Issues

Partial Search Bug.

Issue description

I try to plugin this to my mongoose and it's working as normally but when I do with partial search such as modelOne.find({ 'comment': /hello/i }) it's not working as expected.

Steps to reproduce the issue

  1. Define Model
  2. Find documents that contain with text as hello in comment path
  3. Check the result

Note : I use global plugin to inject req.query for this test.

What's the expected result?

  • The result should count all and divided for calculate as pages
  • Screenshot (2) 'pages' should be 2.

What's the actual result?

  • The result is not count all and not calculate pages
  • Screenshot (2) 'pages' is 1.

Additional details / screenshot

screen shot 2018-06-03 at 01 43 24

screen shot 2018-06-03 at 01 43 35

Does it have "sort" function?

it is a good project,but it seems it can’t use "sort" function because i found the following code doesn‘t show the ideal response

pagination(ProductModel).find(query, null, { sort: 'price' }).page(2).size(4).display(1).exec().then((result) => {
data = JSON.parse(JSON.stringify(result));
// res.send({ records: data.records, page_num: data.display, page: page });
console.log(data);
console.log(data.records);
console.log(data.display);
});

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.