Endpoints for deleting items
In Node-RED, add two new endpoints:
- /deleteCollection
Delete information from the "imageCollection" collection in MongoDB based on the ID.
Here is the format of the endpoint. In the "http in" node, select the PUT method.
- function
msg.query = {
_id: objectid(msg.payload._id)
}
msg.payload = {
$set: {
deleted: true
}
}
return msg;
In the function node, add the "objectid" library.
Об'єкт, який потрібно видалити буде знайдено по _id і йому буде оновлено поле deleted на true.
У вузлі mongoDB out пишемо назву колекцію, яку потрібно оновити, обираємо operation update та Update all matching documents.
The object that needs to be deleted will be found by its _id
, and the deleted
field will be updated to true
for further filtering. This is done to preserve the data.
In the mongodb out node, specify the name of the collection you want to update, select the operation "update," and choose "Update all matching documents."
- /deleteFromGalleryByCollection
Delete information from the "gallery" collection in MongoDB based on the collection ID!
- http in (method)
- function:
msg.query = {
collection: objectid(msg.payload._id)
}
msg.payload = {
$set: {
deleted: true
}
}
return msg;
In the function node, add the "objectid" library.
The object that needs to be deleted will be found by its _id
, and the deleted
field will be updated to true
for further filtering.
In the mongodb out node, specify the name of the collection you want to update, select the operation "update," and choose "Update all matching documents."
No Comments