Query by distance and date with Pymongo [duplicate]

I know this is a very basic question, but I don't understand how to do this.

I know this is a very basic question, but I don't understand how to do this.

I'm using pymongo 3.6.1 in Python 3 and MongoDB 3.4.19. I'm trying to retrieve from the database the records lower than certain date, sorted by distance. By separate the functions are:

db[database].MIDAS_stations.find(
        {
            "loc": {
                "$near": {
                  "$geometry": {
                    "type": "Point",
                    "coordinates": coords
                  }
                }
              }
        }
    )

and

db[database].MIDAS_stations.find(
        {
          "Station start date": {
            "$gt": date1
          }
        }
    )

I have tried with aggregate instead of find, but I still haven't found the way to do this.

I know that there's something similar answered at MongoDB/PyMongo: Querying multiple criteria - unexpected results, but my question is different as it makes use of georeferenced data.

From MongoDB/PyMongo: Querying multiple criteria - unexpected results and https://stackoverflow.com/a/23577413/2313887 I think that the answer to this problem is:

db[database].MIDAS_stations.find(
    {            
        "loc": {
            "$near": {
                "$geometry": {
                    "type": "Point",
                    "coordinates": coords
                }
            }
        },
        "Station start date": {
                "$lt": date1
            }
    }
)

But I'm still uncertain if this is the right approach or if it is really querying for the nearest entries and then selecting only those with a date lower than date1.

Learn MongoDB - MongoDB Tutorial for Beginners - Getting Started with MongoDB - Part 3/3

Learn MongoDB - MongoDB Tutorial for Beginners - Getting Started with MongoDB

What you’ll learn

  • Work with MongoDB with Clarity and Confidence
  • Use 4 tools MongoCHEF, NOSQL Manager, RoboMongo, MongoBooster easily
  • Do Regex, GridFS , Replication , Sharding, Full text search
  • Basic and Advanced CRUD operations using MongoDB
  • Import and Export data from MongoDB
  • Work MapReduce, Embedded Documents,Save&Insert , indexing, capped collections, TTL
  • Bonus section * Use java,C#,PHP,Nodejs to access MongoDB features like CRUD, GridFS
  • Bonus Section * A 50 minutes MongoDB key feature exercises
  • 100+ Quizzes 40+ Activities

Learn More

MongoDB - The Complete Developer’s Guide

The Complete Developers Guide to MongoDB

MongoDB - The Complete Developer’s Guide

Learn MongoDB : Leading NoSQL Database from scratch

Learn NoSQL Databases - Complete MongoDB Bootcamp 2019

Build a CRUD Operation using PHP & MongoBD

MongoDB with Python Crash Course - Tutorial for Beginners

Learn NoSQL Databases from Scratch - Complete MongoDB Bootcamp 2019

AngularJS tutorial for beginners with NodeJS, ExpressJS and MongoDB

MEAN Stack Tutorial MongoDB, ExpressJS, AngularJS and NodeJS

Creating RESTful APIs with NodeJS and MongoDB Tutorial

Learn MongoDB - MongoDB Tutorial for Beginners - Getting Started with MongoDB - Part 1/3

Learn MongoDB - MongoDB Tutorial for Beginners - Getting Started with MongoDB

What you’ll learn

  • Work with MongoDB with Clarity and Confidence
  • Use 4 tools MongoCHEF, NOSQL Manager, RoboMongo, MongoBooster easily
  • Do Regex, GridFS , Replication , Sharding, Full text search
  • Basic and Advanced CRUD operations using MongoDB
  • Import and Export data from MongoDB
  • Work MapReduce, Embedded Documents,Save&Insert , indexing, capped collections, TTL
  • Bonus section * Use java,C#,PHP,Nodejs to access MongoDB features like CRUD, GridFS
  • Bonus Section * A 50 minutes MongoDB key feature exercises
  • 100+ Quizzes 40+ Activities


Learn More

MongoDB - The Complete Developer’s Guide

The Complete Developers Guide to MongoDB

MongoDB - The Complete Developer’s Guide

Building A REST API With MongoDB, Mongoose, And Node.js

Node.js, ExpressJs, MongoDB and Vue.js (MEVN Stack) Application Tutorial

MEAN Stack Tutorial MongoDB, ExpressJS, AngularJS and NodeJS

MongoDB with Python Crash Course - Tutorial for Beginners

Learn MongoDB - MongoDB Tutorial for Beginners - Getting Started with MongoDB - Part 2/3

Learn MongoDB - MongoDB Tutorial for Beginners - Getting Started with MongoDB


What you’ll learn

  • Work with MongoDB with Clarity and Confidence
  • Use 4 tools MongoCHEF, NOSQL Manager, RoboMongo, MongoBooster easily
  • Do Regex, GridFS , Replication , Sharding, Full text search
  • Basic and Advanced CRUD operations using MongoDB
  • Import and Export data from MongoDB
  • Work MapReduce, Embedded Documents,Save&Insert , indexing, capped collections, TTL
  • Bonus section * Use java,C#,PHP,Nodejs to access MongoDB features like CRUD, GridFS
  • Bonus Section * A 50 minutes MongoDB key feature exercises
  • 100+ Quizzes 40+ Activities

Learn More

MongoDB - The Complete Developer’s Guide

The Complete Developers Guide to MongoDB

MongoDB - The Complete Developer’s Guide

Learn MongoDB : Leading NoSQL Database from scratch

Learn NoSQL Databases - Complete MongoDB Bootcamp 2019

Why We Moved From NoSQL MongoDB to PostgreSQL?

How to build GraphQL APIs with Kotlin, Spring Boot, and MongoDB?

Build a CRUD Operation using PHP & MongoBD

MongoDB with Python Crash Course - Tutorial for Beginners

Learn NoSQL Databases from Scratch - Complete MongoDB Bootcamp 2019