Watch keynotes and sessions from, our virtual developer conference.

How to write custom query

I am a newbie to Mongo DB. I wanted to write a custom query

start_time = "10:30"
End_Time  = null
process != "coding"  
@Query(value = "{End_Time: null}, , start_time: {$in: ?1}" )

I need to filter records based on start time is not null and end time is null and other data do not match with the collection


Quick answer by translating your question literally: db.collection.find({start_time: {$ne: null}, end_time: {$eq: null}})

However this is not the most efficient query. You’ll find that as your document count grows, this query will be slower and slower.

If you’re new to MongoDB, please note that building a query in MongoDB is very different from building a query in a regular tabular (e.g. SQL) databases, because how the system works under the hood is very different.

Instead, I would recommend you to check out free courses available in the MongoDB University, which are designed to get you up to speed with MongoDB as quickly as possible.

Best regards,