2

I have an application created in Node.js with a Rethinkdb database, I load images from the application, but from the Data Explorer, to which you can connect from localhost: 8080, I can not delete the loaded elements.

// This is how I show the elements that the table has Data Explorer
r.db("xxxxxxxxxx").table('images')
// And this is, or that shows
{
  "createdAt": Sun Jul 29 2018 16:19:27 GMT+00:00 ,
  "id": "17aac165-e885-4278-9cf2-8a71bca65fe3" ,
  "publicId": "0IERfW4T5wfcjhFjGNftZh" ,
  "src": https:xxxxxxxxxxxxxxxxxxxxxxxx1532881165551.jpg, »
  "tags": [ ],
  "user": {
    "avatar": "www.gravatar.com/avatar/c17a64a79d5bb880c9b002458240fa92" ,
    "name": "" ,
    "username": "pedrito"
  },
  "userId": "pedrito"
}

For more than what I check the javascript documentation of Rethinkdb: (https://www.rethinkdb.com/api/javascript/)

I can not find a way to remove the elements of the images from the table one by one. It's there, but I cannot find the way. The most I can see is how to remove users from another table: r.db ("xxxxxxxx"). Table ("users"). Filter (r.row ['username'] = 'pedrito'). delete (). runpero

I can not delete the images in the same way. I want to do it from Data Explorer, from the graphical part of Rethinkdb. Thanks.

wazz
  • 4,953
  • 5
  • 20
  • 34
gemita
  • 2,686
  • 2
  • 10
  • 17

1 Answers1

2

This question is a bit unclear, if you mean deleting the entire document:

r.db("database").table("table").get("document_id").delete()
database, table, and document_id are placeholders
database: The database the table you are trying to delete from is in
table: The table the document you want to delete is in
document_id: The primary key of the document (default id) that you want to delete

so in this

{ "createdAt": Sun Jul 29 2018 16:19:27 GMT+00:00 , "id": "17aac165-e885-4278-9cf2-8a71bca65fe3" , "publicId": "0IERfW4T5wfcjhFjGNftZh" , "src": https:xxxxxxxxxxxxxxxxxxxxxxxx1532881165551.jpg, » "tags": [ ], "user": { "avatar": "www.gravatar.com/avatar/c17a64a79d5bb880c9b002458240fa92" , "name": "" , "username": "pedrito" } , "userId": "pedrito" }

Your primary key is likely ID, so you would use
r.db("xxx").table("images").get("17aac165-e885-4278-9cf2-8a71bca65fe3").delete()

https://rethinkdb.com/api/javascript/#delete


else, if you mean deleting a specific key, go check this answer to another question https://stackoverflow.com/a/18580552

EDIT: Delete all

r.db('database').table('table').forEach((entry)=>{ return r.db('database').table('table').get(entry('id')).delete(); });

this will delete absolutely EVERYTHING in the table!

EDIT: Delete where key = value

r.db('database').table('table').filter({key:"value"}).forEach((entry)=>{ return r.db('database').table('table').get(entry('id')).delete(); });

This would delete everything in the table where key: "value".

Donovan_DMC
  • 157
  • 1
  • 15
  • Thanks @Donovan_DMC, it works perfectly to eliminate the elements individually, I would just learn, how to eliminate all at once. – gemita Aug 07 '18 at 23:09
  • 1
    @gemita added a little code that would delete every entry in the table, check updated answer. – Donovan_DMC Aug 09 '18 at 23:57
  • 1
    @gemita also added a query where it will delete all where key:value (last one) – Donovan_DMC Aug 10 '18 at 04:20
  • thank you @Donovan_DMV, I apologize for the time it took me to answer, I could not connect until now. Thanks for the support. – gemita Aug 16 '18 at 11:23