2017년 1월 6일 금요일

Document CRUD - Delete

Tags

Remove

collection.remove(selector)
selector에 해당하는 document를 지운다. selector는 _id나 _key를 포함해야하며 collection에 존재하는 값이어야 한다.
remove 메소드가 실행 후, _id, _key, _rev를 포함한 document를 리턴한다.
selector에 _rev를 포함할 경우, _id나 _key에 해당하는 문서를 검색한 후, 해당문서의 _rev와 selector의 _rev를 비교한다. 다를 경우 에러가 발생한다.
collection.remove(selector, options)
아래와 같은 옵션을 줄 수도 있다.
  • waitForSync:
  • overwrite:
  • returnOld:
  • silent:
collection.remove(document-handle)
collection.remove(document-handle, options)
위와 같이 document _id로 삭제할 수 있다.
collection.remove(document-key)
collection.remove(document-handle, options)
_key로도 삭제가 가능하다.
collection.remove(selectorarray)
collection.remove(selectorarray,options)
한 번에 여러 selector로 대상을 삭제할 수 있다.
Examples
Remove a document:
arangosh> a1 = db.example.insert({ a : 1 });
{ 
  "_id" : "example/14754", 
  "_key" : "14754", 
  "_rev" : "_USnzp1W---" 
}
arangosh> db.example.document(a1);
{ 
  "_key" : "14754", 
  "_id" : "example/14754", 
  "_rev" : "_USnzp1W---", 
  "a" : 1 
}
arangosh> db.example.remove(a1);
{ 
  "_id" : "example/14754", 
  "_key" : "14754", 
  "_rev" : "_USnzp1W---" 
}
arangosh> db.example.document(a1);
[ArangoError 1202: document not found]
Remove a document with a conflict:
arangosh> a1 = db.example.insert({ a : 1 });
{ 
  "_id" : "example/14741", 
  "_key" : "14741", 
  "_rev" : "_USnzpzC---" 
}
arangosh> a2 = db.example.replace(a1, { a : 2 });
{ 
  "_id" : "example/14741", 
  "_key" : "14741", 
  "_rev" : "_USnzpzG---", 
  "_oldRev" : "_USnzpzC---" 
}
arangosh> db.example.remove(a1);
[ArangoError 1200: precondition failed]
arangosh> db.example.remove(a1, true);
{ 
  "_id" : "example/14741", 
  "_key" : "14741", 
  "_rev" : "_USnzpzG---" 
}
arangosh> db.example.document(a1);
[ArangoError 1202: document not found]

Remove By Keys

collection.removeByKeys(keys)
key 배열로 찾아 삭제한다. key에 해당하는 문서가 없을 경우 무시된다.
위 메소드는 "removed" 속성으로 삭제된 document의 수를, "ignored" 속성으로 무시된 key의 수를 리턴한다.
Examples
arangosh> keys = [ ];
[ ]
arangosh> for (var i = 0; i < 10; ++i) {
........>   db.example.insert({ _key: "test" + i, value: i });
........>   keys.push("test" + i);
........> }
arangosh> db.example.removeByKeys(keys);
{ 
  "removed" : 10, 
  "ignored" : 0 
}

Remove By Example

collection.removeByExample(example)
example에 해당하는 document를 삭제한다. 아래와 같이 순서대로 옵션을 줄 수 있다.
collection.removeByExample(document, waitForSync)
collection.removeByExample(document, waitForSync, limit)

Examples
arangosh> db.example.removeByExample( {Hello : "world"} );
1


EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:o
:>)
(o)
:p
:-?
(p)
:-s
8-)
:-t
:-b
b-(
(y)
x-)
(h)