MongoDB에서 '좋지 않음'연산자를 어떻게 사용할 수 있습니까?
나는 SQL 사용할 수있는 Like
연산자를 사용 pymongo
,
db.test.find({'c':{'$regex':'ttt'}})
하지만 Not Like
연산자를 어떻게 사용할 수 있습니까?
나는 시도했다
db.test.find({'c':{'$not':{'$regex':'ttt'}})
하지만 오류가 있습니다.
OperationFailure : $ not은 정규식을 가질 수 없습니다.
로부터 문서 :
$ not 연산자는 $ regex 연산자를 사용한 작업을 지원하지 않습니다. 대신 //를 사용하거나 드라이버 인터페이스에서 언어의 정규식 기능을 사용하여 정규식 객체를 만듭니다. // 패턴 일치 표현식을 사용하는 다음 예제를 고려하십시오.
db.inventory.find( { item: { $not: /^p.*/ } } )
수정 (@idbentley) :
{$regex: 'ttt'}
일반적으로 /ttt/
mongodb 와 동일 하므로 쿼리는db.test.find({c: {$not: /ttt/}}
EDIT2 (@KyungHoon Kim) :
파이썬에서는 다음과 같이 작동합니다. 'c':{'$not':re.compile('ttt')}
단어를 포함하지 않는 정규식으로 할 수 있습니다. 또한 $options => i
대소 문자를 구분하지 않는 검색에도 사용할 수 있습니다 .
포함하지 않음 string
db.collection.find({name:{'$regex' : '^((?!string).)*$', '$options' : 'i'}})
대소 문자를 구분하지 않음 string
db.collection.find({name:{'$regex' : '^string$', '$options' : 'i'}})
다음으로 시작 string
db.collection.find({name:{'$regex' : '^string', '$options' : 'i'}})
로 끝나다 string
db.collection.find({name:{'$regex' : 'string$', '$options' : 'i'}})
포함 string
db.collection.find({name:{'$regex' : 'string', '$options' : 'i'}})
이것을 책갈피로 보관하고 필요한 다른 변경 사항에 대한 참조로 보관하십시오. http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/
참고 URL : https://stackoverflow.com/questions/20175122/how-can-i-use-not-like-operator-in-mongodb
'program story' 카테고리의 다른 글
C #을 사용하여 Windows Form에 파일 찾아보기 단추를 추가하는 방법 (0) | 2020.09.16 |
---|---|
Java 7 try-with-resources를 올바르게 사용하고 있습니까? (0) | 2020.09.16 |
Ruby는 기능적인 언어입니까? (0) | 2020.09.16 |
if 절을 종료하는 방법 (0) | 2020.09.16 |
이드의 의미는 무엇입니까? (0) | 2020.09.16 |