Flask MongoEngine 쿼리 filter() 함수 문자열에 대해서 정리해 둬보자. (사실 해본거 하나만 더 적어두자, 해본거니깐)
맨날 = 만 쓰려니
MongoEngine 홈페이지에 가면 다양한 operator 가 있다 쿼리로 사용할 수 있는, 가장 기본적인 예제로 아래와 같이 18세 이하 사용자를 찾아라 같은 예제가 있다.
# Only find users whose age is 18 or less
young_users = Users.objects(age__lte=18)
즉, 필드명에다가 언더스코어 2개를 넣고 원하는 기능어를 넣으면 쿼리 스트링이 완성된다.
필드명__operator
오퍼레이터의 종류는 아래와 같다.
https://docs.mongoengine.org/guide/querying.html#query-operators
- ne – not equal to
- lt – less than
- lte – less than or equal to
- gt – greater than
- gte – greater than or equal to
- not – negate a standard check, may be used before other operators (e.g. Q(age__not__mod=(5, 0)))
- in – value is in list (a list of values should be provided)
- nin – value is not in list (a list of values should be provided)
- mod – value % x == y, where x and y are two provided values
- all – every item in list of values provided is in array
- size – the size of the array is
- exists – value for field exists
내가 시도해 본것은 in 이라는 기능어..
즉, 10살 12살 14살 사용자를 찾아라 하면
young_users = Users.objects(age__in = [10,12,14])
이렇게 하면 된다는 것..
(음.. '=' 는 항상 써야 하는 거군)
관련 추천 사이트
https://www.tutorialspoint.com/mongoengine/mongoengine_query_operators.htm
MongoEngine - Query Operators - Tutorialspoint
MongoEngine - Query Operators In addition to = operator to check equality, the following logical operators are defined in MongoEngine. ne not equal to lt less than lte less than or equal to gt greater than gte greater than or equal to not negate a standard
www.tutorialspoint.com
BJ.
Jesús Mirón García 님의 사진, 출처: Pexels
'IT > DB' 카테고리의 다른 글
우분투 18.04 LTS MongoDB 설치 및 설정, 관리자 계정 추가 정리본 (0) | 2021.07.08 |
---|---|
MongoDB 연결된 상태 보기 (0) | 2021.07.01 |
mongodb - Flask mongoengine 필드 동일값을 그룹으로 묶기 (0) | 2021.06.15 |
mongodb - Flask mongoengine 필드로 정렬하는 방법 (0) | 2021.06.15 |
mongodb - Flask mongoengine을 이용하여 필드 추가, 삭제 (0) | 2021.06.11 |