MongoDB Agregue $ desenrolle $ coincida con la fecha: ¿qué me perdí?
Soy nuevo en MongoDB y estoy tratando de trabajar con agregaciones. Hago parcialmente lo que estoy buscando pero tengo un comportamiento extraño con las fechas.
Información de MongoDB
Versión: 2.2.0
Sistema operativo: Windows 7
Objetivo
Obtenga todos los comentarios creados después de '2012-11-22'
Veamos un ejemplo:
Datos
db.blogs.save([ {
title : "X this is my second title",
author : "max",
posted : new Date(),
pageViews : 10,
tags : [ "good", "nice" ],
comments : [ {
"_id" : ObjectId("50ac9fdb53a900bcb4be46d9"),
author : "john",
text : "pretty awesome",
create : ISODate("2012-12-20T00:00:00.000Z")
}, {
"_id" : ObjectId("50ac9fd003a900bcb4be46d9"),
author : "sam",
text : "this is bad",
create : ISODate("2012-12-22T00:00:00.000Z")
} ],
other : {
foo : 5
}
}, {
title : "X this is my title",
author : "bob",
posted : new Date(),
pageViews : 5,
tags : [ "fun", "good", "fun" ],
comments : [ {
"_id" : ObjectId("50ac55db53a900bcb4be46d9"),
author : "matthieu",
text : "bof bof",
create : ISODate("2012-12-21T00:00:00.000Z")
}, {
"_id" : ObjectId("50ac55db53a900bcb4b226d9"),
author : "sam",
text : "this s bad",
create : ISODate("2012-12-22T00:00:00.000Z")
} ],
other : {
foo : 6
}
}, {
title : "X NEW ELEMENT",
author : "emil",
posted : new Date(),
pageViews : 33,
tags : [ "bad", "hehe", "cool", "nice" ],
comments : [ {
"_id" : ObjectId("50ac55db531100bcb4b226d9"),
author : "emilie",
text : "could be better",
create : ISODate("2012-12-21T00:00:00.000Z")
}, {
"_id" : ObjectId("50ac55db101100bcb4b226d9"),
author : "samuel",
text : "maybe a good one",
create : ISODate("2012-12-20T00:00:00.000Z")
} ],
other : {
foo : 9
}
}, {
title : "X Y NEW ELEMENT",
author : "marc",
posted : new Date(),
pageViews : 33,
tags : [ "bad", "hehe", "cool", "nice" ],
comments : [ {
"_id" : ObjectId("50ac55db101100bcb4baa6d9"),
author : "sam",
text : "hehe",
create : ISODate("2012-11-20T00:00:00.000Z")
}, {
"_id" : ObjectId("50ac55db101ab0bcb4baa6d9"),
author : "daniel",
text : "yeehhhh hoho",
create : ISODate("2012-11-23T00:00:00.000Z")
} ],
other : {
foo : 9
}
} ])
Ejemplo 1: OK con cadenas coincidentes
Devuelve todos los 'comentarios' del usuario 'sam':
db.blogs.aggregate( [
{ $unwind: "$comments" },
{ $match: { 'comments.author' : "sam" } },
{ $group: { _id: "$comments" } }
] )
Esta devolución solo comenta cuando la propiedad 'autor' es 'sam'.
Ejemplo 2: problema con las fechas?
esta agregación es (para mí) la misma que la anterior, pero en lugar de 'autor' coincidente, coincido con la propiedad de fecha 'crear':
db.blogs.aggregate( [
{ $unwind: "$comments" },
{ $match: {
'comments.create' : {
$gt: ISODate("2012-11-22T00:00:00Z")
}
} },
{ $group: { _id: "$comments" } }
] )
Pero si prueba esta agregación, verá que algunos comentarios contienen fechas 'crea' más bajas que '2012-11-22'. Por ejemplo, se devuelve un comentario con ID '50ac9fdb53a900bcb4be46d9'.
Espero solo comentarios con fechas mayores que '2012-11-22' ... Supongo que me perdí algo ...
Gracias