$date in collections (HTTP)
|
For details about additional languages, see: |
You can use $date to represent dates as Unix timestamps in the JSON payload of a Data API command:
"date_of_birth": { "$date": 1690045891 }
The following example includes a date in an insertOne command:
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/COLLECTION_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"insertOne": {
"document": {
"date_of_birth": { "$date": 1690045891 },
"name": "Jane Doe"
}
}
}'
The following example uses the date to find and update a document with the updateOne command:
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/COLLECTION_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"updateOne": {
"filter": {
"date_of_birth": { "$date": 1690045891 }
},
"update": { "$set": { "message": "Happy birthday!" } }
}
}'
The following example uses the $currentDate update operator to set a property to the current date:
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/COLLECTION_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOneAndUpdate": {
"filter": {"$and": [
{"title": "Into Shadows of Tomorrow"},
{"author": "Nicole Wright"}
]
},
"update": {
"$currentDate": {
"due_date": true
}
}
}
}'