我如何在featherjs中过滤?

时间:2016-12-16 00:34:02

标签: javascript feathersjs nedb

我试图用羽毛js中的nedb过滤数据库。

我使用此命令但它不起作用。

我使用此命令但它不起作用。

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}`);
});

没有获得过滤器

请帮帮我

没有获得过滤器

请帮帮我

2 个答案:

答案 0 :(得分:0)

尝试删除","你有" db"在这一行:

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

答案 1 :(得分:0)

.find会返回Promise。要获得promise的结果,请在.then中注册回调:

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

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