Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (47.6k points)

I would like to execute the following query:

db.mycollection.find(HAS IMAGE URL)

What should be the correct syntax?

3 Answers

0 votes
by (106k points)

The query for “is not null” in Mongodb in pymongo you can use the following query:-

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

This is because pymongo represents mongo "null" as python "None".

0 votes
by (107k points)

Follow the following syntax:

db.collection1.find({ 'fieldname1' : { $exists: true, $ne: null } });

When $exists is true, $exists matches the documents that contain the particular field, including documents where the field value is null. If the value is false, the query returns only the documents that do not consist of the field. $ne picks the documents where the value of the field is not equal to the particularized value. This incorporates documents that do not contain the field.

0 votes
by (3.1k points)

The following Two methods can be used to resolved it  
Use the $ne operator with null, or combine $exists and $ne to make sure the field both exists and is non-null. 
Example 1: Using $ne 
 
db.collection.find({ fieldName: { $ne: null } }) 
 
This query returns documents where fieldName is explicitly not null. 
Example 2: Using $exists and $ne 
db.collection.find({ fieldName: { $exists: true, $ne: null } }) 
 
It returns only the documents where fieldName exists and is not null. These techniques are generally used for filtering out the MongoDB database documents. 

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
asked Sep 26, 2019 in SQL by chandra (29.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...