'Parse ISODate to object after aggregate
I am trying to query a MongoDB database with Rust. My code is as follows:
let mut data = Vec::<ManagementReportResult>::new();
let level_docs = doc!{
"$unwind": "$managements"
};
let project_result = doc!{
"$project": {
"client": "$clientCode",
"product": "$productCode",
"case": 1,
"action": "$managements.action",
"createdAt": 1
}
};
let pipeline = vec![level_docs, project_result];
let mut cursor = self.collection.aggregate(pipeline, None).await?;
while let Some(management) = cursor.next().await {
let item: ManagementReportResult = from_document(management?)?;
data.push(item);
}
The parsing struct looks like this:
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all="camelCase")]
pub struct ManagementReportResult {
pub client: String,
...
#[serde(with = "chrono_datetime_as_bson_datetime")]
pub created_at: DateTime<Utc>
}
but on this line:
let item: ManagementReportResult = from_document(management?)?;
I get the error:
error: DeserializationError {
message: "invalid type: map, expected a formatted date and time string or a unix timestamp",
}
If I print the document this is what is has in the date field: "createdAt": DateTime( 2021-11-23T05:17:14.892Z, ),
Any held would be much appreciated
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
