我试图在一系列文档中总结一些值,没有运气.
这是文件
db.Cuentas.find().漂亮的()
{
"Agno": "2013",
"Egresos": [
{
"Fecha": "28-01-2013",
"Monto": 150000,
"Detalle": "Pago Nokia Lumia a @josellop"
},
{
"Fecha": "29-01-2013",
"Monto": 4000,
"Detalle": "Cine, Pelicula fome"
}
],
"Ingresos": [],
"Mes": "Enero",
"Monto": 450000,
"Usuario": "MarioCares"
"_id": ObjectId(....)
}
Run Code Online (Sandbox Code Playgroud)
因此,我需要"Eguos"中所有"Monto"的总和为"Usuario":"MarioCares".在这个例子154000
使用聚合我使用:
db.Cuentas.aggregate(
[
{ $match: {"Usuario": "MarioCares"} },
{ $group:
{
_id: null,
"suma": { $sum: "$Egresos.Monto" }
}
}
]
)
Run Code Online (Sandbox Code Playgroud)
但我总是得到
{ "result" : [{ "_id" : null, "suma" : 0 }], …Run Code Online (Sandbox Code Playgroud) 所以,我正在使用此代码从我的服务器创建报告PDF文件
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
List<Integer> cartas1 = new ArrayList<Integer>();
DeudorDAO DDAO = new DeudorDAO();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
baos = DocumentoCartaCobranza.CrearDocumento(
getServletContext().getRealPath("static/images/pdf_banner.jpg"),
getServletContext().getRealPath("static/images/firmaJG.png"),
getServletContext().getRealPath("static/images/firmaAB.jpg"),
DDAO.getDatosFullDeudores(cartas1)
);
} catch (DocumentException e) {
e.printStackTrace();
}
OutputStream os = response.getOutputStream();
baos.writeTo(os);
os.flush();
os.close();
Run Code Online (Sandbox Code Playgroud)
和
public static ByteArrayOutputStream CrearDocumento(
String imgCabecera,
String imgFirma,
String imgAbogado,
java.util.List<Deudor> carta1) throws DocumentException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
PdfWriter pdfw = null;
pdfw = PdfWriter.getInstance( Documento, …Run Code Online (Sandbox Code Playgroud)