4
Я получаю сообщение об ошибке при попытке изменить поле даты в моей коллекции.
Это схема, и я хотел бы, чтобы изменить sent
поле, которое хранит даты:
> db.complaints.findOne()
{
"_id" : ObjectId("55e5990d991312e2c9b266e3"),
"complaintID" : 1388734,
"product" : "mortgage",
"subProduct" : "conventional adjustable mortgage (arm)",
"issue" : "loan servicing, payments, escrow account",
"subIssue" : "",
"state" : "va",
"ZIP" : 22204,
"submitted" : "web",
"received" : "2015-05-22",
"sent" : "2015-05-22",
"company" : "green tree servicing, llc",
"response" : "closed with explanation",
"timely" : "yes",
"disputed" : ""
}
Это запрос, и сообщение об ошибке я получаю:
db.complaints.aggregate([
{$project:
{_id:0,
sent: 1,
Year:{$year:"$sent"},
Month: {$month:"$sent"},
Day: {$dayOfMonth: "$sent"},
product : 1}},
])
> db.complaints.aggregate([
... {$project:
... {_id:0,
... sent: 1,
... Year:{$year:"$sent"},
... Month: {$month:"$sent"},
... Day: {$dayOfMonth: "$sent"},
... product : 1}},
...
... ])
assert: command failed: {
"errmsg" : "exception: can't convert from BSON type String to Date",
"code" : 16006,
"ok" : 0
} : aggregate failed
Error: command failed: {
"errmsg" : "exception: can't convert from BSON type String to Date",
"code" : 16006,
"ok" : 0
} : aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
at (shell):1:15
2015-09-12T13:16:22.876+0100 E QUERY Error: command failed: {
"errmsg" : "exception: can't convert from BSON type String to Date",
"code" : 16006,
"ok" : 0
} : aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
at (shell):1:15 at src/mongo/shell/assert.js:13
> db.complaints.aggregate([
... {$project:
... {_id:0,
... sent: 1,
... Year:{$year:"$sent"},
... Month: {$month:"$sent"},
... Day: {$dayOfMonth: "$sent"},
... product : 1}},
...
... ])
assert: command failed: {
"errmsg" : "exception: can't convert from BSON type String to Date",
"code" : 16006,
"ok" : 0
} : aggregate failed
Error: command failed: {
"errmsg" : "exception: can't convert from BSON type String to Date",
"code" : 16006,
"ok" : 0
} : aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
at (shell):1:15
2015-09-12T13:21:08.767+0100 E QUERY Error: command failed: {
"errmsg" : "exception: can't convert from BSON type String to Date",
"code" : 16006,
"ok" : 0
} : aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
at (shell):1:15 at src/mongo/shell/assert.js:13
>
будет что конвертировать даты во всех коллекции ? – tottihope
@tottihope Он не будет их преобразовывать, но он преобразует результат, как вы описали. – JohnnyHK
Большое спасибо JohnnyHK. Он преобразует строку на сегодняшний день, когда он переформатирует документы. – tottihope