I have a mongo images metadata collection consisting of the following fields: camera_name(str), photographer_name(str), resolution(str), image_size(int in MB, rounded) and timestamp(10 digit UNIX timestamp)
I want to run 2 queries only:
- Given camera_name, return records which have timestamp <= 1639457261(sample UNIX timestamp). The records must be sorted in descending order
- Given camera_name, photographer_name, resolution, image_size and timestamp, I want to retrieve the records, sorted in the descending order of the timestamp entered.
I created 2 indexes:
{ "camera_name": 1, "timestamp": -1 }
{ "camera_name": 1, "photographer_name": 1, "resolution": 1, "image_size": 1, "timestamp": -1}
The first index works but when I run the query for the second index, no records are returned. I am sure that there are records present in the collection and I am expecting to get at least 10 records while running the second query but it is returning an empty list.
Is there something wrong the way the index is configured? Thanks
Here is the sample data:
{"camera_name": "Nikon", "photographer_name": "Aaron", "resolution": "1920x1080", "image_size": "3", "timestamp": 1397232415}
{"camera_name": "Nikon", "photographer_name": "Paul", "resolution": "1920x1080", "image_size": "4", "timestamp": 1717286853}
{"camera_name": "Nikon", "photographer_name": "Beth", "resolution": "720x480", "image_size": "1", "timestamp": 1503582086}
{"camera_name": "Nikon", "photographer_name": "Aaron", "resolution": "1920x1080", "image_size": "4", "timestamp": 1500628458}
{"camera_name": "Nikon", "photographer_name": "Paul", "resolution": "1920x1080", "image_size": "6", "timestamp": 1407580951}
{"camera_name": "Canon", "photographer_name": "Beth", "resolution": "1920x1080", "image_size": "5", "timestamp": 1166049453}
{"camera_name": "Canon", "photographer_name": "Paul", "resolution": "720x480", "image_size": "2", "timestamp": 1086317569}
{"camera_name": "Canon", "photographer_name": "Beth", "resolution": "720x480", "image_size": "1", "timestamp": 1400638926}
{"camera_name": "Canon", "photographer_name": "Aaron", "resolution": "720x480", "image_size": "1", "timestamp": 1345248762}
{"camera_name": "Canon", "photographer_name": "Paul", "resolution": "1920x1080", "image_size": "5", "timestamp": 1462360853}
{"camera_name": "Fuji", "photographer_name": "Beth", "resolution": "720x480", "image_size": "2", "timestamp": 1815298047}
{"camera_name": "Fuji", "photographer_name": "Shane", "resolution": "720x480", "image_size": "3", "timestamp": 1666493455}
{"camera_name": "Fuji", "photographer_name": "Beth", "resolution": "1920x1080", "image_size": "5", "timestamp": 1846677247}
{"camera_name": "Fuji", "photographer_name": "Beth", "resolution": "1920x1080", "image_size": "5", "timestamp": 1630996389}
{"camera_name": "Fuji", "photographer_name": "Shane", "resolution": "720x480", "image_size": "2", "timestamp": 1816829362}
The queries I execute:
- camera_name=Nikon and timestamp<=1503582086 should return 4 records
- camera_name='Fuji' ,photographer_name='Beth', resolution='1920x1080', image_size='5' and timestamp<=1900000000 should return 2 records but I'm getting 0 records