Rick Moss
Rick Moss

Reputation: 926

backbone.js and rails

I have a rails app where i have a Contact model and with an embedded address document so a contact can have multiple address's all stored in the one document.

I want to use backbone on the front end to have a contact page to edit contact details ie name, age and then also to add many address's.

What is the way to do this ? Should i be posting the whole contact model including all address's each time a field is changed or an address is added / removed ?

Or should i be doing pop / push atomic operations some how?

I am using mongomapper by the way.

I hope someone can explain the way this works?

thanks rick

Upvotes: 1

Views: 276

Answers (1)

Adam Comerford
Adam Comerford

Reputation: 21682

First, have a look at this question which discusses the full update versus the incremental update approach:

Voting system with Backbone.js

That is for a simple counter, so the $inc operator is not what you are looking for, however you can use other atomic operators (like $set), for in place updates, see here:

http://www.mongodb.org/display/DOCS/Atomic+Operations

The last thing you then will want to think about is the document size. If you allow the user to have an infinite number of addresses then be prepared to incur hits if/when the document exceeds its original size (plus some padding). That can mean more IO and updating indexes etc. A full discussion is beyond the scope of this question, but check out this page for a start:

http://www.mongodb.org/display/DOCS/Updating

Hope that helps!

Upvotes: 4

Related Questions