I' cercando di utilizzare framework aggregazione (con il rubino) e proiettare la data così:MongoDB: non può convertire da tipo BSON EOO alla Data
db['requests'].aggregate([
{"$project" => {
_id: 0,
method: '$method',
user: '$user',
year: {'$year' => '$timestamp'}
}}])
il documento è come questo:
{
_id: ObjectId("5177d7d7df26358289da7dfd"),
timestamp: ISODate("2013-04-12T03:58:05+00:00"),
method: "POST",
status: "200",
inputsize: "874",
outputsize: "4981",
user: "131"
}
ma ottengo il seguente errore:
Mongo::OperationFailure: Database command 'aggregate' failed: (errmsg: 'exception: can't convert from BSON type EOO to Date'; code: '16006'; ok: '0.0').
questo è strano perché funziona correttamente se corro questo sul esattamente lo stesso che ho db s importato con mongorestore.
Apparentemente l'ordine della matrice passato per aggregare() è importante. Se hai campi in cui qualcosa è omesso, ti consigliamo di aggiungerlo alla partita $ e avere la corrispondenza $ come primo elemento dell'array. Cioè > db.user_account.aggregate ([{$ match: {"uts": {$ exists: true}, "chan_key": "333261c7a72650a95c68d30cd70"}}, {$ project: {"period_month": {$ month: "$ uts "}}}, {$ gruppo: {_id: {" period_month ":" $ periodo_month "}," numero ": {$ somma: 1}}}]) –