MongoDB Aggregate – 展开,组和项目

使用收集Users ,是否有可能检索以下独特的组织/业主名单? 如果当前设置不可行,是否有可能通过一个查询从两个ID链接集合中获得相同的结果? 目前,使用mongoose我只能检索一组组织名称: 当前查询 userModel.aggregate([ { $unwind:'$organisations' } , { $group: { name: '$organisations.name' } } ]) 用户 { "_id" : ObjectId("53f4a94e7c88310000000001"), "email" : "bob@example.com", "organisations" : [ { "name" : "OrgOne", "isOwner" : true } ] }, { "_id" : ObjectId("53f4a94e7c88310000000002"), "email" : "ash@something.com", "organisations" : [ { "name" : "OrgOne" } ] […]

没有域的SSL证书

我有一堆node.js应用程序通过websockets(ws://)向apache站点提供信息。 该网站本身没有域名,并通过其IP地址访问(这是不可谈判的,不幸的是…) 问题如下: 没有安全连接,浏览器将阻止ws://stream量,所以我必须使用SSL和安全websockets wss:// 如果没有域名,除了生成自签名证书之外,我无法保护连接。 自我生成的证书不被浏览器信任,并显示错误“证书不可信…”。 最后一次chrome更新使得通过消息更加恼人。 除此之外, IP定期更换,并在发生时发送给用户(2-3人)。 因此,针对特定IP颁发的证书并不理想(如果免费,我可以处理刷新证书的麻烦)。 有没有人有办法解决吗 ?

使用本地mongodb模块查询MongoDB中的bson字段

我有一个使用Mongo DB C#驱动程序的程序来填充文件的mongo集合。 如果我运行一个查找 client.connect('mongodb://127.0.0.1:27017/foo', function(err, db) { var things = db.collection('things'); things.find({}, ['ThingId']).limit(1).toArray(function(err, docs) { console.log(docs[0]); } } 看看存储的是什么,然后我看到类似的东西 {_id:1234235341234,ThingID:{_bsontype:'Binary',sub_type:3,position:16,buffer:<Buffer a2 96 8d 7f fa e4 a4 48 b4 80 4a 19 f3 32 df 8e>}} 我已经阅读了文档,并尝试如下的东西: console.log(mongojs.Binary(docs[i].SessionId.buffer, 3).value()); 但是我不能将ThingId作为UUIDstring打印到控制台 我绝对不能查询它! 我的目标是通过传递GUIDstring来查询,以便我可以使用Idsselect文档我知道生成的C#(可以看到使用RoboMongo) 任何帮助非常感谢! 更新:正如@ wes-widner指出的那样,mongo c#驱动程序团队有一个UUID助手js文件,它可以帮助在不同的UUID之间进行转换,我们可以在RoboMongo中直接使用它来查询。 但它使用的BinData仅在mongo shell中可用,而且我不知道如何使用节点访问它。 链接的答案显示了如何在使用mongo shell时使用uuidHelper和BinData进行查询,本质上我要问的是如何在节点

无法使用Grunt和shell(Codebox)下载ace权限错误(虚拟Macine)

从Codebox 0.8.1工作 这是一个包含Codebox用来构build其编辑器插件的3个文件的Gist 。 我在运行virtualbox ubuntu / precise64通过vagrantpipe理cmd运行npm安装所有我很好,但是当我运行sudo npm start我收到以下内容: Building addons in ./addons/ (force=false) Optimizing cb.files.editor error for optimization of cb.files.editor options= { baseUrl: 'addons/cb.files.editor', name: 'client', out: '/project/addons/cb.files.editor/addon-built.js', paths: { 'require-tools': '/project/core/cb.addons/require-tools' }, optimize: 'uglify', map: { '*': { css: 'require-tools/css/css', less: 'require-tools/less/less', text: 'require-tools/text/text' } } } { [Error: Command failed: node […]

Node.js REPL在函数声明或函数expression式之后自动声明下划线?

今天我发现了一些关于node.js的奇怪现象: $ node > console.log(_) ReferenceError: _ is not defined at repl:1:13 at REPLServer.defaultEval (repl.js:130:27) at bound (domain.js:257:14) at REPLServer.runBound [as eval] (domain.js:270:12) at REPLServer.<anonymous> (repl.js:277:12) at REPLServer.EventEmitter.emit (events.js:107:17) at REPLServer.Interface._onLine (readline.js:202:10) at REPLServer.Interface._line (readline.js:531:8) at REPLServer.Interface._ttyWrite (readline.js:812:14) at ReadStream.onkeypress (readline.js:101:10) > function foo() {} undefined > console.log(_) undefined undefined 我创build一个函数expression式后发生同样的事情: $ node > console.log(_) […]

了解Express中的callback

我想从passport.js身份validation文档中了解以下示例: app.get('/login', function(req, res, next) { passport.authenticate('local', function(err, user, info) { if (err) { return next(err); } if (!user) { return res.redirect('/login'); } req.logIn(user, function(err) { if (err) { return next(err); } return res.redirect('/users/' + user.username); }); })(req, res, next); //***UNSURE ABOUT THIS*** }); 我明白代码的作用 – 但是我不知道callback函数结尾的(req, res, next)是什么。 为什么有必要? 它是否提供(err, user, info) ? 如果是这样的话,为什么我没有看到更多的以参数结尾的函数调用 […]

风帆给“get”参数赋予了“404”。

我有SPA帆船应用程序。 所有路线我的SPA应用程序,首先进入欢迎行动控制器。 '/*' :{ controller : 'Web/welcomeController', skipAssets : true } 所有其他路线使用像API,阿贾克斯请求。 这条路线“/ *”只用于第一个渲染页面。 所有其他人提供angularjs。 在那里,一个路由有点参数。 http://localhost:1337/search?lat=40.714545&long=-74.007112 我得到404错误。 所有这些都是由skipAsset参数引起的,它忽略了带有内容点的url。 我需要控制器也跳过像图像,JS等资产资源。 但正确处理请求与获取参数的内容点/ ? /?lat=40.714545&long=-74.007112

ZeroMQ和Sails.js

在Sails.JS应用程序中添加ZeroMQ套接字的build议方式是什么? 我应该为处理套接字configuration和连接定义一个sails钩子,并在全局范围内使用不同控制器的套接字对象,还有其他更好的解决scheme吗?

Mongoose填充返回null

我的代码包含2个模型,内容和电影。 电影有对内容的参考。 在'电影'查询当我尝试填充内容',返回null。 内容模型 'use strict'; var mongoose = require('mongoose'), validators = require('./validators'), Schema = mongoose.Schema; var contentType = ['M']; var ContentSchema = new Schema({ createdOn: { type: Date, default: Date.now }, name: { type: String, required: true, unique: true, trim: true }, type: { type: String, required: true, enum: contentType, trim: true }, releaseDate: […]

从构造函数获取原型,而无需在v8中创build实例

我正在编写一个导出对象构造函数的v8节点扩展,如本文档中所示。 一些函数将其他类的实例作为参数,所以我想检查这些参数的types,类似于这个答案的build议。 它暗示的一件事是将对象的原型与临时实例中已知的正确原型进行比较 Local<Object> obj = constructor->NewInstance(); prototype = Persistent<Value>::New(obj->GetPrototype()); if (instance->GetPrototype() == prototype) { //… 然而,我的一些构造函数是复杂的,并将其他类的实例作为参数,所以这将是非常不方便的。 我的类初始化函数看起来像这样(从链接模板中获取): void MyObject::Init(Handle<Object> exports) { // Prepare constructor template Local<FunctionTemplate> tpl = FunctionTemplate::New(New); tpl->SetClassName(String::NewSymbol("MyObject")); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype tpl->PrototypeTemplate()->Set(String::NewSymbol("plusOne"), FunctionTemplate::New(PlusOne)->GetFunction()); constructor = Persistent<Function>::New(tpl->GetFunction()); exports->Set(String::NewSymbol("MyObject"), constructor); } 是否有可能从FunctionTemplate或constructor FunctionTemplate获得一个prototype对象,如果我得到一个新的MyObject实例obj obj->GetPrototype()将比较相等与prototype ? 我尝试使用tpl->PrototypeTemplate()->NewInstance()和constructor->GetPrototype() ,但似乎都没有正确的值。 这是我想要做的一个完整的例子: #include <node.h> #include <v8.h> using namespace […]