5

Suppose we have reminder list of users as -

  • Reminder 1
  • Reminder 2
  • Reminder 3

User can change order of list using drag and drop on UI. eg user drags Reminder 3 and drops in place of Reminder 1. So now and even after user refresh, list should be -

  • Reminder 3
  • Reminder 1
  • Reminder 2

How can I achieve this in mongodb efficiently ? (I'm using NodeJS with Express and Mongoose JS)

Community
  • 1
  • 1

1 Answers1

0

You can use something like sorting_id for each reminder which should be unique, and update it with nodejs in the db when someone changes the order by dragging it, and while searching, just sort them by sorting_id

Dark Lord
  • 415
  • 5
  • 16
  • I thought of this, but how to deal if list is result of query. Eg if user queries some documents like - Reminder 2 (order_id =2) Reminder 10 (order_id=10) Reminder 198 (order_id=198) and moves Reminder 198 to Reminder 10 position, I might need to update all order_id of Reminder 11 to Reminder 198 by increment with 1. – ab-Sol-Invictus Apr 09 '17 at 15:39
  • just interchange the ids, if you are showing only 10 and 198 and he is interchanging, it doesn't necessarily mean that he is putting 198 id at 10 and 10 id at 11 id, maybe he is just changing them, maybe if we can actually define the behaviour overall, it will be easy to find a solution – Dark Lord Apr 10 '17 at 09:02