'collection.removeByExample(example)' method is used to remove documents by example.
Signature
collection.removeByExample(example)
collection.removeByExample(document, waitForSync)
collection.removeByExample(document, waitForSync, limit)
If you set ‘waitForSync’ parameter to true, then ArangoDB enables the operation to be in force sync with disk. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied.
‘limit’ parameter is used to limit number of removals.
Let’s experiment with an example.
127.0.0.1:8529@abc_org> db.user.toArray() [ { "_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" : "31893", "_id" : "user/31893", "_rev" : "_cR9QHBy---", "firstName" : "Shanmuk", "lastName" : "Rao", "age" : 33, "id" : 6 }, { "_key" : "31916", "_id" : "user/31916", "_rev" : "_cR9Qdi2---", "firstName" : "Jaideep", "lastName" : "Gera", "age" : 35, "id" : 7 }, { "_key" : "31930", "_id" : "user/31930", "_rev" : "_cR9QxTy---", "firstName" : "Sailu", "lastName" : "PTR", "age" : 36, "id" : 8 }, { "_key" : "31944", "_id" : "user/31944", "_rev" : "_cR9RJMy---", "firstName" : "Chamu", "lastName" : "M", "age" : 33, "id" : 9 }, { "_key" : "31958", "_id" : "user/31958", "_rev" : "_cR9RbtC---", "firstName" : "Ravi", "lastName" : "Chandra", "age" : 35, "id" : 10 } ]
As you see above snippet, user collection has 3 documents with the age 35.
Let’s delete any 2 documents with age 35.
db.user.removeByExample({"age": 35}, false, 2)
127.0.0.1:8529@abc_org> db.user.removeByExample({"age": 35}, false, 2) 2 127.0.0.1:8529@abc_org> db.user.toArray() [ { "_key" : "23404", "_id" : "user/23404", "_rev" : "_cRhMFQ6---", "id" : 5, "firstName" : "Gireesh", "lastName" : "Amara", "age" : 30 }, { "_key" : "31893", "_id" : "user/31893", "_rev" : "_cR9QHBy---", "firstName" : "Shanmuk", "lastName" : "Rao", "age" : 33, "id" : 6 }, { "_key" : "31930", "_id" : "user/31930", "_rev" : "_cR9QxTy---", "firstName" : "Sailu", "lastName" : "PTR", "age" : 36, "id" : 8 }, { "_key" : "31944", "_id" : "user/31944", "_rev" : "_cR9RJMy---", "firstName" : "Chamu", "lastName" : "M", "age" : 33, "id" : 9 }, { "_key" : "31958", "_id" : "user/31958", "_rev" : "_cR9RbtC---", "firstName" : "Ravi", "lastName" : "Chandra", "age" : 35, "id" : 10 } ]
Previous Next Home
No comments:
Post a Comment