在Sails.js中从MongoDB获取数据

我是Sails.js的新手。 我试图从我的Mongo Db数据库“TestDB”中获取数据,我有一个名为“Components”的集合,所以我创build了一个名为Components的Model,其中包含了我的集合 Components.js module.exports = { attributes: { TaskId: { type: 'string', required: true }, CompName: { type: 'string' }, InitialAttr: { type: 'string' }, Value: { type: 'string' } } }; ComponentsController.js module.exports = { GetComponentList : function(req, res){ Components.find({ CompName: 'ImageComponent'}).exec(function(err, data) { if (err) return next(err); res.json(data); }); } }; 路线: […]

node.io问题与内置模块

所以我可以像运行一个js文件 $ node file.js 用node.io里面的文件做事情。 但如果我去命令行,并尝试键入一个内置的模块,就像它显示在https://www.npmjs.org/package/node.io $ node.io query "http://www.reddit.com/" a.title 我只是回到-bash:找不到node.io:命令 这可能是一件非常愚蠢的事情,但我无法弄清楚。

如何使用loopback.io将相关实体包含在REST中

我正在使用Strongloop的环回工具来创build一个REST服务。 我想知道如何定义什么相关的实体,当请求一个模型返回。 我在文档中看到,你可以发送一个像GET /api/members?filter[include]=posts这样的请求GET /api/members?filter[include]=posts并且会返回相关的post模型,并且我发现你可以做一个像GET /api/members?filter[include]=posts&filter[include]=comments这样的请求GET /api/members?filter[include]=posts&filter[include]=comments来获取post和评论,但有没有一种方法可以在代码或生成的json文件中定义,您希望某个关系在请求模型时总是被返回?

在q-io / http.request上进行ETIMEDOUT

使用q-io / http拉入网页失败。 我想我一定会错过一些明显的东西 – 因为这是我认为是一个非常直接的例子。 编辑:Windows 8,节点11.13 var http = require('q-io/http') var url = 'http://www.google.com' ; http.request({ method: 'GET', uri: url }). then(function (response) { console.log(response) }). fail(function (err) { console.error(err) }); 这是输出: { state: 'pending' } > { [Error: connect ETIMEDOUT] stack: 'Error: connect ETIMEDOUT\n at exports._errnoException (util.js:742:11)\n at Object.afterConnect [as oncomplete] (net.js:989:19)', […]

如何sorting,select和查询mongoose中的子文档

所以我想sorting子文档,但也select和一切。 看来我不能用普通的查询,所以我尝试瓦特/ aggregate mongoose = require("mongoose"); mongoose.connect("localhost:27017", function(err) { mongoose.connection.db.dropDatabase(); Story = mongoose.model("Story", { title: String, comments: [{ author: String, content: String }] }); sample = new Story({ title: "Foobar", comments: [ { author: "A author", content: "1 Content" }, { author: "B author", content: "2 Content" } ] }); sample.save(function(err, doc) { Story.aggregate([ { […]

Mongoose,nodejs,全文search

我正在尝试使用Mongoose和nodejs设置一个简单的关键字全文search,这是迄今为止的代码: var db = mongoose.createConnection('localhost', config.mongoDbName) , ContSchema = Schema({ 'idUser': String, 'title': String, 'category': String, 'slug': String, 'description': String }) .index({ 'title':'text', 'description':'text' }) , ContModel = db.model('Cont', ContSchema); db.on('error', function (err) { console.error.bind(console, 'Mongoose connection error:' + err); }); db.once('open', function () { process.stdout.write('Connection to mongodb db done…'); }); 然后我做search查询: var getAllBy = […]

希望使用Gulp来创build独立的HTML文件的个人分布

基本上我正在寻找一个Gulp插件来打开这样一个目录: /app – htmlfile1.html – htmlfile2.html – htmlfile3.html – /css -cssmain.css -/js -global.js 把它变成这样: /dist -/htmlfile1 – htmlfile1.html – /css -cssmain.css -/js -global.js – /htmlfile2 – htmlfile2.html – /css -cssmain.css -/js -global.js – /htmlfile3 – htmlfile3.html – /css -cssmain.css -/js -global.js 有关如何完成这样的构build系统的任何想法?

如何添加字段的JavaScript数组中的每个对象没有循环?

有没有方法来添加一个字段的每个对象的Javascript数组没有循环呢? 就像是 array.each(function (index, object){ object[newField] = anotherArray[index]; });

mongoose用自己的ObjectId引用自我引用抛出:强制转换为ObjectId失败

我正在使用nodejs,mongoose,我试图build立一个shema包含通过父母的引用。 父应该是对DataType的引用。 var DataTypeSchema = new Schema({ _id: String, label: { type: String, required: true }, comment: { type: String }, url: { type: String, required: true }, parent: { type: Schema.Types.ObjectId, ref: 'DataType' }, values: [] }); var DataType = mongoose.model('DataType', DataTypeSchema); module.exports.DataType = DataType; 每个DataType都有自己的ID (不是由mongo生成),我认为这是一个导致问题的地方。 它抛出一个错误转换objectid失败的价值“数字”的path“父母” ,其中数字是ID为“数字”已保存在数据库中的对象。 谢谢

输出在Sublime Text中的node.js输出中被截断

为了尽可能简洁,我试图弄清楚是否有一种方法允许控制台使用console.log()显示对象的完整内容。 我在Sublime Text 3中使用了传递到控制台的node.js。我没有任何问题运行代码本身,只是显示输出。 我有一个链接列表对象,我创build像这样: { value: 1, next: { value: 2, next: { value: 3, next: { value: 4, next: { value: 5, next: null}}}}} 当它输出到控制台时,它看起来类似于以下内容: { value: 1, next: { value: 2, next: { value: 3, next: [Object]}} 总之,整个对象是不可见或可扩展的。 有什么办法可以强制控制台更详细,并显示整个对象?