How to remove a specific element from an inline array in RethinkDB?

sample data, for example:

{ 'id': 1, 'things': [{'name': 'a'},{'name': 'b'},{'name': 'c'}] } 

how to update a document by deleting an array element named "b" from the inline array?

 r.table('test') .get(1) .update({things: r.row('things')????}); 
+6
source share
1 answer

You can use the update command along with filter to filter the elements in the array and go to update .

 r.table('30848200').get(1).update(function (row) { return { 'things': row('things') .filter(function (item) { return item('name').ne('b') }) } }) 

Basically, you will overwrite things with a filtered array.

+10
source

Source: https://habr.com/ru/post/989137/


All Articles