[mongodb, 몽고디비] How do you query for “is not null” in Mongo?

[Question]

I would like to execute a following query:

db.mycollection.find(HAS IMAGE URL)

What should be the correct syntax?

 

[Answer]

This will return all documents with a key called "IMAGE URL", but they may still have a null value.

db.mycollection.find({"IMAGE URL":{$exists:true}});

This will return all documents with both a key called "IMAGE URL" and a non-null value.

db.mycollection.find({"IMAGE URL":{$ne:null}});

Also, according to the docs, $exists currently can't use an index, but $ne can.

Edit: Adding some examples due to interest in this answer

Given these inserts:

db.test.insert({"num":1, "check":"check value"});
db.test.insert({"num":2, "check":null});
db.test.insert({"num":3});

This will return all three documents:

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

db.test.find();

This will return the first and second documents only:

db.test.find({"check":{$exists:true}});

This will return the first document only:

db.test.find({"check":{$ne:null}});

This will return the second and third documents only:

db.test.find({"check":null})

 

[출처] https://stackoverflow.com/questions/4057196/how-do-you-query-for-is-not-null-in-mongo

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86153
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78648
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95383
904 [spark] Spark 튜닝하기 file 졸리운_곰 2021.03.06 1291
903 [spark] PySpark와 pandas 데이터 프레임 간의 변환 최적화 file 졸리운_곰 2021.03.04 1674
902 [데이터사이언스] 데이터 과학자를위한 3 가지 훌륭한 디자인 패턴, 3 Great Design Patterns for Data Scientists file 졸리운_곰 2021.03.04 779
901 [hadoop] Python으로 Hive 연결하기 졸리운_곰 2021.03.04 1502
900 Data Engineering - Apache Spark Dataframe 10분만에 훑어보기 졸리운_곰 2021.03.04 1868
899 [데이터분석] 시계열 데이터에 AI를 사용하는 이유는 무엇입니까? file 졸리운_곰 2021.02.28 1191
898 [데이터분석] AI 예측 및 이상 탐지를위한 시계열 데이터 전처리 file 졸리운_곰 2021.02.28 1031
897 [hadoop][java][MapReduce] 맵리듀스 원리와 그 과정 졸리운_곰 2021.02.28 1653
896 [데이터분석] bitcoin analysis 비트 코인 시계열 데이터에 대한 AI 이상 탐지 file 졸리운_곰 2021.02.27 1588
895 [spark] pyspark 설치하기 (windows 10) file 졸리운_곰 2021.02.26 1661
894 [hadoop][mapreduce][csv file] [Reference] : Hadoop MapReduce Join & Counter with Example file 졸리운_곰 2021.02.23 1534
893 [hadoop][mapreduce][csv file] Hadoop & Mapreduce Examples: Create First Program in Java file 졸리운_곰 2021.02.23 1855
892 [mongodb , 몽고디비] How to Use MongoDB Comparison Query Operators in Java 졸리운_곰 2021.02.19 1508
891 Apache Spark란? 졸리운_곰 2021.02.19 1508
890 [apache spark] [Spark Programming]1. Apache Spark 개요 및 설치 file 졸리운_곰 2021.02.19 19627
889 [Oracle, 오라클 데이터베이스] java.sql.SQLException: ORA-00911: 문자가 부적합합니다. file 졸리운_곰 2021.02.19 1063
» [mongodb, 몽고디비] How do you query for “is not null” in Mongo? 졸리운_곰 2021.02.19 1268
887 스파크 Spark - 윈도우10에서 빅데이터 실습 세팅 및 시작하기 file 졸리운_곰 2021.02.17 1313
886 스파크(Spark) 3.0.0 설치 on Windows 10 file 졸리운_곰 2021.02.17 1598
885 [oracle, 오라클] 오라클 MERGE INTO 문으로 있으면 UPDATE 없으면 INSERT 한번에 수행하기 졸리운_곰 2021.02.16 1044
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED