0

My aim is sort rfc 822 timestamp format which is stored in Mongodb as a pubdate field . I do not want to fetch all the records using PHP/Python and sort using it as lot of records will be required to be placed on memory. I am putting down an example below how my mongo fields look , like this I have million number of records -

"pubdate" : [ "Sun, 22 Jun 2014 06:52:56 +0000" ], "title" : [ "Al-Qaida militants kill senior Yemeni army officer" ]
"pubdate" : [ "Sun, 21 Jun 2014 06:52:56 +0000" ], "title" : [ "He went to paradise" ]
"pubdate" : [ "Sun, 20 Jun 2014 06:52:56 +0000" ], "title" : [ "Legacy of USA" ]

I require sorting on pubdate field which in turn will be called by PHP

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
user3136348
  • 55
  • 1
  • 10
  • Are these strings? They look like strings, in fact strings within an array. If so then you are just about right out of luck as if they are not proper date object types or a lexical string then you cannot sort them with expected results. – Neil Lunn Jul 08 '14 at 08:12
  • Yes , I have extracted it from rss , field using scrapy – user3136348 Jul 08 '14 at 08:38
  • What you needed to do was "convert" those dates to a correct BSON type when importing. Various languages have various means to parse the date string. This question has been asked **many** times before. – Neil Lunn Jul 08 '14 at 08:53
  • possible duplicate of [How do I convert a property in MongoDB from text to date type?](http://stackoverflow.com/questions/2900674/how-do-i-convert-a-property-in-mongodb-from-text-to-date-type) – Neil Lunn Jul 08 '14 at 08:53
  • It is not perhaps a duplicate , Even if i convert it to date type how will I do a sort on it ? – user3136348 Jul 08 '14 at 12:51

0 Answers0