Remove a single anonymous message from the authenticated user’s inbox. The route verifies the caller’s session, reads the targetDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dev0302/nextjs-project-1/llms.txt
Use this file to discover all available pages before exploring further.
messageId from the URL query string, and issues a single findByIdAndUpdate call with a MongoDB $pull operator to atomically excise the matching subdocument from the user’s messages array. The full updated user document is returned in the response.
Method and URL
Authentication
Required. The request must carry a valid NextAuth JWT session cookie. The server callsgetServerSession(NEXT_AUTH_CONFIG) to resolve the caller’s identity before touching the database.
Query Parameters
The MongoDB
ObjectId (as a hex string) of the message to delete. Obtain this value from the _id field in the response of GET /api/get-messages. If this parameter is absent the server returns 404.curl Example
Responses
201 — Message Deleted
The message was found and removed. The response body contains the full updated user document underdata.
401 — Not Authenticated
No valid session was found.404 — Not Found
Returned in two cases: themessageId query parameter was missing, or no user document was found for the session’s _id.
500 — Internal Server Error
An unexpected error occurred during the database update.Response Fields
true when the message was successfully removed; false on any error.Human-readable description of the outcome.
The full updated
User document returned by findByIdAndUpdate with { new: true }. Present only on a 201 response. Contains the user’s messages array with the deleted entry already removed.How $pull Works
The deletion is executed with a single atomic MongoDB operation:
$pull is a MongoDB update operator that removes all elements from an array that match a given condition. Here it targets the subdocument whose _id equals messageId. The operation is atomic — no separate read-then-write is needed, and no other messages in the array are affected.