我有一大堆这样的文件:
{
_id: '1',
colors: [
{ value: 'red', count: 2 },
{ value: 'blue', count: 3}
]
shapes: [
{ value: 'cube', type: '3d' },
{ value: 'square', type: '2d'}
]
},
{
_id: '2',
colors: [
{ value: 'red', count: 7 },
{ value: 'blue', count: 34},
{ value: 'yellow', count: 12}
]
shapes: [
{ value: 'prism', type: '3d' },
{ value: 'triangle', type: '2d'}
]
}
Run Code Online (Sandbox Code Playgroud)
通过使用$unwind和$addToSet,如下所示:
db.getCollection('coll').aggregate([{$unwind:"$colors"},{$unwind:"$shapes"},{$group:{_id:null,colors:{$addToSet:"$colors"},shapes:{$addToSet:"$shapes"}])
Run Code Online (Sandbox Code Playgroud)
我可以得到以下信息:
{
"_id" : …Run Code Online (Sandbox Code Playgroud) 如标题所示,我正在使用Express我的webapp。
目前,我的代码如下所示:
API控制器
var mongoose = require('mongoose');
var Doc = mongoose.model('Document');
var sendJSONresponse = function(res, status, content) {
res.status(status);
res.json(content);
};
// "/api/documents"
module.exports.listAllDocuments = function(req, res) {
var stream = Doc.find().stream();
stream.on('data', function (chunk) {
res.write(JSON.stringify(chunk));
}).on('error', function (err) {
console.log('Error: ' + err);
}).on('end', function () {
res.end();
});
};
Run Code Online (Sandbox Code Playgroud)
var stream = Doc.find().stream();我希望利用而不是使用aggregate()。
像一样find(),aggregate()应该是可读流,对吗?
但是,当我简单地find()用一个aggregate()电话代替时,它似乎不起作用。
它说类型错误:Object #<Aggregate> has no method 'stream'。有什么方法可以流式传输聚合的JSON数据 …
我正在寻找一个与Angular一起使用的时间线小部件,模块或指令,看起来像这样:http://www.cssscript.com/demo/simple-scrollable-timeline-chart-with-d3-js-d3-时间线/(见下面链接到GitHub).我没有时间从头开始写这样的东西.
令人惊讶的是,我找不到一个.如果有人指出我,或者有人可以慷慨地为https://github.com/commodityvectors/d3-timeline编写一个原生的AngularJS指令,我将不胜感激.我知道; 这要求太多了.