Skip to content

Commit

Permalink
deleteDocument Function
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Jul 5, 2023
1 parent bc265e5 commit cc17f4e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.4

- Added deleteDocument function

# 1.0.3

- Simplify `onSync` logic to just pass any entity.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stuyk/cross-resource-cache",
"version": "1.0.3",
"version": "1.0.4",
"description": "add mongodb database saving to cross resource environments for altv",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
21 changes: 21 additions & 0 deletions src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,24 @@ export async function getAll<T extends { _id: ObjectId }>(
return undefined;
}
}

/**
* Deletes a single document by `_id`
*
* If the document was deleted it will return `true`.
*
* @export
* @param {string} _id
* @param {string} collection
* @return {Promise<boolean>}
*/
export async function deleteDocument(_id: string, collection: string): Promise<boolean> {
const client = await getMongoClient();

try {
const result = await client.collection(collection).deleteOne({ _id: new ObjectId(_id) });
return result.acknowledged;
} catch (err) {
return false;
}
}

0 comments on commit cc17f4e

Please sign in to comment.