根据日期(月)使用node.js和mongodb过滤并重新排列结果 [英] Filter and re-arrange results using node.js and mongodb according to date(month)

查看:141
本文介绍了根据日期(月)使用node.js和mongodb过滤并重新排列结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Node.JS和Express创建了一个服务器。数据库是MongoDB,ORM是Mongoose。这是我必须做的。

I created a server using Node.JS and Express. Database is MongoDB and ORM is Mongoose. Here's what I have to do.

    {
        "_id": "5788fcf7bfecf0c135178418",
        "incomeDate": "2012-01-01T00:00:00.000Z",
        "name": "Sales",
        "type": "Sales one",
        "amount": 5500,
        "__v": 0
    }

这是我从数据库中获取的对象。我想按日期(实际按月)过滤这些对象。我将使用Angular Charts在图表中显示月收入。 ( https://jtblin.github.io/angular-chart.js/ ) - >角度条形图。

This is the object I'm getting from database. I want to filter these objects by date ( actually by month). I'm going to display monthly income in a chart using Angular Charts. (https://jtblin.github.io/angular-chart.js/) -> Angular Bar chart.

因此,如果特定月份没有金额,则列表中应为零(0)。列表必须是这样的。列表中有12个元素。这只是一个例子。

So if there's no amount in a specific month, there shoud be zero (0) in the list. The list must be like this. there are 12 elements of the list. This is just an example.


[200,1200,10,0,124,542,1254,500,0,1254,36,87]

[200,1200,10,0,124,542,1254,500,0,1254,36,87]

我怎么能在node.js和mongoose中这样做?必须使用incomedate进行过滤并在node.js中执行一些代码.....

How can I do this in node.js and mongoose ? Have to filter using incomedate and do some code in node.js.....

推荐答案

将其称为:

var date = new incomeDate();

{$group: {date: date.getMonth()}

嘿运行你的代码,看看你得到了什么错误,我们努力解决它们。

Hey run your codes and see what error you get and we work around to fix them.

这篇关于根据日期(月)使用node.js和mongodb过滤并重新排列结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆