db.command.aggregate.dateFromString
1. Operator Description
Function: Converts a date/time string to a date object.
Declaration: db.command.aggregate.dateFromString({dateString,timezone})
2. Operator Parameters
Field | Type | Required | Description |
---|---|---|---|
dateString | string | Required | Date string |
timezone | string | No | Timezone |
3. Sample Code
// Sample code in the Cloud Function environment
const tcb = require('@cloudbase/node-sdk')
const app = tcb.init({
env: 'xxx'
})
const db = app.database()
const $ = db.command.aggregate
exports.main = async (event, context) => {
const res = await db
.collection('dates')
.aggregate()
.project({
_id: 0,
date: $.dateFromString({
dateString: '2019-05-14T09:38:51.686Z'
})
})
.end()
console.log(res.data)
}
The output is as follows:
{
"date": ISODate("2019-05-14T09:38:51.686Z")
}