Tuesday 6 June 2017

Deleting an element from redis list having stringified JSON as element of list in Node.js

I want to delete comment belonging to a post from redis. I am using list as my data structure. I tried using the LREM command(Syntax: LREM Key count value), but the value in my case is a stringified JSON object. So to delete any comment for given post, everytime I have to put that whole JSON as the value in LREM. The JSON looks as:

"{\"_id\":\"5935374b535\",\"author\":{\"_id\":\"58382eae771\",\"user_id\":\"58382eae77149\",\"username\":\"hello_37\",,\"post_id\":{\"_id\":\"5919abd3b6a\",\"images\":[],\"description\":\"\",\"title\":\"Testing post\"},\"user_id\":\"58382eae77149d3d02204369\",\"mentions\":[\" cool comment5\"]\"is_approved\":true,\"text\":\" cool comment5\",\"__v\":0}"

This works, but is not a good approach. Can I delete the comment just using id for that comment(_id)? I am not able to find any command for deletion in list other LREM which uses the complete value of element in list.



via Subham Kumar

No comments:

Post a Comment