Search code examples
javascriptfeathersjsnedb

How i can filter in featherjs?


I'm trying to filter database with nedb in feather js.

I'm using this command but it doesn't work.

I'm using this command but it doesn't work.

const NeDB = require('nedb');
const feathers = require('feathers');
const rest = require('feathers-rest');
const socketio = require('feathers-socketio');
const bodyParser = require('body-parser');
const errors = require('feathers-errors');
const service = require('feathers-nedb');

const db = new NeDB({
  filename: './db-data/messages',
  autoload: true
});

// Create a feathers instance.
var app = feathers()
  // Enable REST services
  .configure(rest())
  // Enable Socket.io services
  .configure(socketio())
  // Turn on JSON parser for REST services
  .use(bodyParser.json())
  // Turn on URL-encoded parser for REST services
  .use(bodyParser.urlencoded({
    extended: true
  }));

// Connect to the db, create and register a Feathers service.


// Set the `paginate` option during initialization


app.use('/messages', service({
  Model: db,
}));


app.service('messages').find({

  query: {

    $skip: 5,
    $limit: 2
  }
});



// Create a dummy Message
app.service('messages').create({
  text: 'Oh hai!'
}).then(function(message) {
  console.log('Created message', message);
});



// Start the server.
const port = 3030;

app.listen(port, function() {
  console.log(`Feathers server listening on port ${port}`);
});

not get filter

please help me

not get filter

please help me


Solution

  • .find returns a Promise. To get the result of the promise register a callback in .then:

    app.service('messages').find({
      query: {
    
        $skip: 5,
        $limit: 2
      }
    })
    .then(messages => {
      console.log('Found messages', messages);
    });