-1

I am using lowdb as my database. So the database file db.json looks like below.

{
  "posts": {
    "user1" : {
       id: 1,
       published: false
     },
     "user2" : {
       id: 2, 
       published: true
     }
  },
  "comments": {
    "article1" : {
       id: 1,
       postId: 1
     },
    "article2" : {
       id: 2,
       postId: 2
     }
  }
}

What I want to achieve is that on match of certain condition, remove the posts key with values. So my db file should look like below.

{
  "comments": {
    "article1" : {
       id: 1,
       postId: 1
     },
    "article2" : {
       id: 2,
       postId: 2
     }
  }
}

Any guide will be of great help.

user10518298
  • 169
  • 1
  • 16

1 Answers1

0

You can use unset method to remove the post key from lowdb database

db.unset(`posts`).write()