asked on
How to add a new record (document) between two existing records in a MongoDB Database collection
I would like to be able to insert a new document between existing documents in a MongoDB database collection. I will explain what I need through an example of a collection containing just 5 records (the actual collection contains several hundered thousand records).
In a MongoDB database collection I have 5 records. The first record is the one that was added to the this collection first of all and the second was added after the first and so forth (I know this is obvious). When I pull data from this collection in my App, the first records comes out first and the second record comes out after the first and so forth . I would now like to add a sixth record such that when I pull data from this table this 6th record should be pulled out before the 2nd record but after the first record. So this means I need to insert a new record (document) between the first and the 2nd record. I would appreciate help with code that will help me achieve this.