Schema for a changeable ordering

Hello,

I’d like to create a good schema that allows a fast change of the (sort) order - the client should be able to add, remove and rearrange the order of the document(s) within a group (perhaps with a group identifier or set).

Also every single document can get often called directly by it’s ID - and only this data is needed, not the complete group.

It’s recommend to return the current order index with each single document.

Using a key {…, order: 1} for every document in the group results in updating every single document with a new query (I am new to mongoDB - please correct me if I am wrong) to change and/or increment the order value.

Or using a set [‘id1’, ‘id2’, …] or just inserting the whole document (they aren’t big - this post has nearly the same size ;-)) in this set.

Not sure what’s the best solution and how to update this data.
Also I think I will have limit the group size for example to 999 items. But this is open and will depend on the performance.

Thanks for your help!

2 Likes

I also want to know how to implement what @Xairoo is looking after. Can any humble person help me out as well please?

Hi @Venkatesh_Nadar,

Can you provide some examples and details on what the current use case is? Please also elaborate on any examples provided with regards to schema. Additionally, please provide as much information on the use case as possible. For example - MongoDB version, requirements, etc.

In saying so, some of the following pages may be of use regarding schemas:

Regards,
Jason