I have a mongodb collection in which document is stored in the below format
{
"_id": {
"host_ip": "192.41.15.161",
"date": "2020-02-02T08:18:09.207Z"
},
"path": "/apache_pb.gif",
"request": "GET /apache_pb.gif HTTP/1.0",
"status": 200
}
where "host_ip" and "date" should be composite primary key i.e. (unique together) and there exists an _id index, which I think is created based on these two fields
So, how can I query based on host_ip and date together so that the "_id" index can be utilized?
Tried using
db.collection.find({_id: {host_ip: "192.41.15.161", date: {$gte: ISODate('2020-02-02T08:00:00:00.000Z')}}})
, but it does not work, it does not even return the record which should match. Is it not the correct way to query?
Query like
db.collection.find({"_id.host_ip": "192.41.15.161", "_id.date": {$gte: ISODate('2020-02-02T08:00:00:00.000Z')}})
, worked but it does not use the index created on "_id"