Saturday, 28 August 2021

ArangoDB: Remove documents by keys

'collection.removeByKeys(keys)' method is used to remove the documents by keys.

 

Signature

collection.removeByKeys(keys)

 

This method return the object that contains information about number of removed documents and number of ignored documents.

 

What if there is no document associated with given key?

Simply ignored, no exception is thrown.

 

Let’s experiment with an example.

127.0.0.1:8529@abc_org> db.user.toArray()
[ 
  { 
    "_key" : "17091", 
    "_id" : "user/17091", 
    "_rev" : "_cRe1GKu---", 
    "id" : 2, 
    "firstName" : "Gopi", 
    "lastName" : "Battu", 
    "age" : 33 
  }, 
  { 
    "_key" : "17095", 
    "_id" : "user/17095", 
    "_rev" : "_cRe1H-6---", 
    "id" : 4, 
    "firstName" : "Venkat", 
    "lastName" : "Ptr", 
    "age" : 35 
  }, 
  { 
    "_key" : "23404", 
    "_id" : "user/23404", 
    "_rev" : "_cRhMFQ6---", 
    "id" : 5, 
    "firstName" : "Gireesh", 
    "lastName" : "Amara", 
    "age" : 30 
  }, 
  { 
    "_key" : "user-7", 
    "_id" : "user/user-7", 
    "_rev" : "_cRhodqC---", 
    "id" : 7, 
    "firstName" : "Joel", 
    "lastName" : "Battu", 
    "age" : 35, 
    "hobbies" : [ 
      "cricket" 
    ] 
  } 
]

Remove the documents with keys 17091, 12345, user-7.

127.0.0.1:8529@abc_org> db.user.removeByKeys(["17091", "12345", "user-7"])
{ 
  "removed" : 2, 
  "ignored" : 1 
}




 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment