Tag: 水线

find()等于和喜欢在帆

我想执行这样的查询, select * from user where user.status = 'ban' and user.status = 'new' and user.username like 'fo%' // in code I will get this from req.param('user') 我知道如何做到这一点, var username = req.param('user'); var status = req.param('status'); User.find().where({ status : [status, 'new'], username : username }).exec(function(err, users){ console.log(users); }); 但是我不知道如何使用“like”作为用户名。 我应该怎么做。 谢谢。

填充()中的条件不起作用

我想查询图片表与指定的用户,但我的代码不工作。 Image.find().populate('user', { id : '1' }).sort({ updatedAt: 'desc' }).exec(function(err, images){ console.log(images) }); 它仍然显示与所有用户。 如何查询? 谢谢。

水线:访问模型中的填充值

我正在使用sails.js来开发我的第一个应用程序。 我有一个水线模型如下所示。 //ModelA.js module.exports = { attributes: { //more attributes userId: { model: 'user' }, //more attributes } }; 我在我的一个控制器中使用模型,如下所示。 ModelA.find(options) .populate('userId') .exec(function (err, modelA) { //some logic //modelA.userId is undefined here res.json(modelA); //userId is populated in the JSON output }); 如何访问模型中的填充值?

build立查询来获取js中的聊天对话消息

比方说,我有以下描述的模型架构,以添加我的帆应用程序中的2个用户之间的一些聊天function。 例如,如果我有用户A发送消息给用户B,则用户B将回复给用户A,用户A将始终在两个用户之间创build2个对话。 所以我的问题是我如何查询两个对话,从A和B获得消息。我尝试了这样的事情,但也许是一个简单的逻辑。 // User Model attributes: { username: { type: 'string', required: true, unique: true, }, conversations_sender: { collection: conversation, via: 'sender' }, conversations_recipient: { collection: conversation, via: 'recipient' } } // Conversation model attributes: { sender: { model: user }, recipient: { model: user }, messages: { collection: 'message', via: 'conversation' } } […]

Sails.js:水线或filter不工作

我正在开发一个sails.js应用程序使用默认水线 。 我有一系列的类别和位置,如下所示。 var categoryOrFilter = [1,2,3]; var locationsOrFilter = [8,9,10]; 我正在尝试在我的model上编写一个where ,它将过滤属于categoryOrFilter中的至less一个categoryOrFilter以及位于locations中的至less一个locations的模型项目。 我的模型如下所示。 attributes: { category: { model: 'category' }, location: { model: 'location' } } 我写了我的查询如下所示。 Model.find() .where({ or: [{ "category": categoryOrFilter }] }) .where({ or: [{ "location": locationsOrFilter }] }) .exec(function (err, modelItem) { //Some logic }); 我的categoryOrFilter值不被考虑。 我的locationOrFilter值工作完美。 我究竟做错了什么?

Sails.js数据与水线航行电梯缺less

我正在使用waterline orm,它默认使用sails.js。 我最近意识到我的数据刚刚在我的MySQL数据库中失踪,当我做帆升降机。 我的模型configuration是改变。 有没有人遇到类似的问题? 这是可怕的。

水线插入一对多关联与返回ID

我有两个模型,文档和文件,每个文档可以有许多文件,而每个文件只能属于一个文档(一对多)。 我有以下代码试图插入一个文件。 水线将返回与所有相关文件的文档模式,但我想要的只是我刚刚插入的文件的最后一个插入ID。 Document.findOne({hash: documentHash}).exec(function(err, document) { if (err) {return res.serverError(err);} document.files.add({ name: req.param("name"), creator: req.param("userID"); }); document.save(function(err, model) { if (err) {return res.serverError(err);} //it returned the Document modal, but I want the last insert id console.log(model); res.send(1); }); });

帆:我怎样才能读取Excel文件数据到JSON格式

我想上传Excel文件后,读取本地文件夹中的excel文件。 var fs = require('fs'); uploadFile.upload ({ // don't allow the total upload size to exceed ~10MB maxBytes: 10000000, saveAs: function(uploadFile, cb) {cb(null,Date.now()+uploadFile.filename ); },dirname: '../../assets/uploads' },function whenDone(err, uploadedFiles) { if (err) { console.log("error"); return res.negotiate(err); } // If no files were uploaded, respond with an error. if (uploadedFiles.length === 0) { return res.badRequest('No file […]

在Waterline获取插入的logging

如何获得Waterline插入的logging? 注意:我正在使用sails.js 我的代码: record=MyModel.create({ … }).exec(function createdFile(err, _record){ … return _record; }); record总是undefined但是它被插入到数据库中,我想在插入之后将json中插入的logging返回给客户端。 ( res.json({'message':jsonx(record)}); )。 谢谢

Nodejs:Waterline + Caolan / Async:绑定函数

使用Balderdashy /水线和Caolan /asynchronous ,我试图平行severa水线查询。 到目前为止,我发现的更短的是: const tasks = { foos: (function(){return this.exec.bind(this);}).apply(Foo.find({foo: "foo"})), bars: (function(){return this.exec.bind(this);}).apply(Bar.find({bar: "bar"})) }; return async.parallel(tasks, function(err, out){ // Here, err contains the potential error, and out looks like {foos:[…],bars:[…]} }); 我试图做bars: Bar.find({bar: "bar"}).exec但async似乎apply该函数与另一个对象作为范围…所以我不能find一种方法来做到这一点更简单的方法。 请注意,我想避免将函数封装在另一个函数中,因为它是我想要查找替代方法的语法: bars: function(cb){Bar.find({bar: "bar"}).exec(cb)} 感谢您的帮助。