Woody
Posts: 0
Joined: Thu Dec 04, 2014 2:37 pm

Services for insert, update, delete of subdocuments objects in an array

KUDOS

Thanks for a great tool and support. After one week I've managed to create a working piece of software.

BACKGROUND

However, given that I was new to Mongodb, I had made the classic relational model of Master-Detail tables (documents). I have "Projects" with multiple "Areas".

The downside is of course, that I have to do cascading deletes on occasion (which your server code script in this forum helped tremendously) and making the app work offline becomes difficult because I have to manage Master-Detail offline without GUIDs etc.

As such, I am now redesigning the app with "Areas" as an array of objects in the "Projects" table / document.

I was able to modify the update project service to create a new "area".

QUESTION


Do you have any examples on how to query, update and delete an existing area? e.g., a subdocument object in an array inside the master document?

Actually just a recommended strategy would be useful as I think I can work out the details.

Do I need to implement a "row" GUID for each area? Can I refer to them by array position?

Woody
Posts: 0
Joined: Thu Dec 04, 2014 2:37 pm

Services for insert, update, delete of subdocuments objects in an array

I dont' know if I took the right approach but here's what I did and it does "work":

ul
liPerform all child (Area) actions through Update service on parent (Project)
/liliGenerate a GUID for all child records via javascript
/liliGet all children and search within array to find the child (Area) being displayed, updated or deleted
/liliReconstitute full children array and PUT back via parent update action
/li/ul

Bit of work but now I can move forward with taking the app offline.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Services for insert, update, delete of subdocuments objects in an array

Woody,

It's not fully clear why don't you use GUID provided by DB collections? For example when you get info from DB you can leave these items _id. And use it to link items.. etc..

Please show us your current implementation and then we could help you with that.

Regards.

Woody
Posts: 0
Joined: Thu Dec 04, 2014 2:37 pm

Services for insert, update, delete of subdocuments objects in an array

DB collections only provides GUID for the parent ("Project" in my case). I am storing child objects ("Areas") as an array within the parent collection. As such (as far as I know), the DB doesn't create a an identifier for each child in the array.

My original, always on-line implementation uses the pointers between two collections Projects and Areas, but I wanted to try to do it with just a single collection -- again in hopes of making it possible to work offline when necessary.

Hope that makes sense.

In any case, I managed to get it to work.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Services for insert, update, delete of subdocuments objects in an array

Woody,

Okay, understand now.

You have child items inside single row. So row is your parent and inside array - is your child item..

So here is two main ways in this case:

  1. Generate GUID for each item. (this is more difficult way).

  2. Use order number for each item. (but you should be aware of it when order should changed (for example when middle items should be deleted) ).

    I guess more preferable to use 2nd way cause of 1st way has overflow by implementation and data-overflow.

    Please let me know if you have some problems with understanding of 2nd way.

    Regards.

Return to “Issues”