Exploring the power of combining MongoDB with Backbone.js

Currently, I am developing a few Backbone applications that require Ruby on the backend for connecting to the database. However, I am exploring options to eliminate Ruby from my demos (although I understand this poses security risks in production).

Upon visiting the AngularJS website, I came across an interesting example (http://jsfiddle.net/api/post/library/pure/) where they connected directly to the Mongolabs service without the need for a backend language.

// This code snippet demonstrates cloud persistence in Mongolab - https://mongolab.com
angular.module('mongolab', ['ngResource']).
    factory('Project', function($resource) {
      var Project = $resource('https://api.mongolab.com/api/1/databases' +
          '/angularjs/collections/projects/:id',
          { apiKey: '4f847ad3e4b08a2eed5f3b54' }, {
            update: { method: 'PUT' }
      }
  );

  Project.prototype.update = function(cb) {
    return Project.update({id: this._id.$oid},
        angular.extend({}, this, {_id:undefined}), cb);
  };

  Project.prototype.destroy = function(cb) {
    return Project.remove({id: this._id.$oid}, cb);
  };

  return Project;
});

I'm curious if achieving a similar setup is possible in Backbone as well. If it is, could you guide me on how to do so? I attempted to study the approach used by AngularJS to replicate it, but I am still relatively new to Backbone and struggling to grasp their methodology.

Answer №1

The convenience of the AngularJS example lies in its ability to handle Mongolab operations without requiring you to write extensive boilerplate code. Simply make a direct service call using ajax:

$.ajax( { url: "https://api.mongolab.com/api/1/databases/
                     your_db/collections/your_collection?apiKey=your_key",
      data: JSON.stringify( { "your_field" : "your_data" } ),
      type: "POST",
      contentType: "application/json" } );

Note:

MongoLab Now Offers Support for Two-Factor Authentication

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving an array through a promise

I have developed an express application that includes a function intended to return a promise which is then returned from an endpoint. Below is the function within my codebase where I handle promises: In my express endpoint: app.get('/logs', ( ...

Refreshing chosen value (html) utilizing buttons

In my code, I have a Select that allows me to choose the number of a chapter I want to display (see image): <select name="select" onchange="javascript:sliders[0].goTo(value);"> <?php for($i=1; $i<$row['nbChapitre']+1; $i++){ ?> ...

Transfer the elements from one array list to another array list

I need to duplicate the array list below $scope.medicinelist = [ {medicine: 'AMLOPRES 5MG TABLET'}, {medicine: 'ARGIPREG SACHET'}, {medicine: 'ALCIPRO 500MG TABLET'} , {medicine: 'PROLOMET AM 50MG TABLET'}, {medic ...

Angular 2 Integration for Slick Carousel

Greetings! I have recently ventured into Angular 2 and am currently attempting to get a carousel plugin called slick up and running. After some trial and error, I have successfully implemented it as a Component in the following manner: import { Component ...

Searching for multiple array elements based on their values can be achieved by using various techniques

I am trying to find a way to select multiple elements from an array that share the same value. When I use array.find(), it only returns the first element that matches the condition. For example, in the code below, only "Donald Trump" is displayed in the co ...

Error: Trying to access the '$getIndex' property of an undefined value is not possible

I'm struggling with fixing this error. Can anyone offer some guidance? TypeError: Cannot read property '$getIndex' of undefined at Scope.<anonymous> (angularfire.min.js:1) at Parser.filter.fnInvoke (angular.js:10101) at OPERATOR ...

Sort a Laravel 4.2 collection by a different field or the output of a function

I am working with a mongo database and I need to write some Eloquent code to manipulate fields before using them in WHERE or ORDER BY clauses. It's similar to running a SQL query like: Select ag.*, ht.* from agency as ag inner join hotel as ht on ag ...

Universal Navigation Search Component for Vue Router

Just starting out with Vue and frontend development. I'm attempting to create a universal navigation bar in Vue Router using bootstrap vue, complete with a search bar feature. However, because I have placed my navigation bar in App.vue, I am encount ...

Please ask Java to receive a JSON parameter for converting a JSON array into a Java array

Essentially, my goal is to pass a Java String array to a JavaScript array, then pass this array via JSON to a JSP page, where I can parse it as a Java array. I attempted the following: JSONArray arr = new JSONArray(); JSONObject tmp; for(int i = 0; ...

Verifying Age through Date of Birth

I'm currently seeking a way to validate a date of birth field that is entered as text in a dd/mm/yyyy format using jQuery Masked Input. I want to ensure the correct format is used by also utilizing the dateITA:true additional methods for validation. ...

Using the MySQL WHERE clause in combination with JavaScript to filter data

I could use some assistance. I am transferring text between pages using local storage. How can I condition the variable called "retrievedObject" that holds the text value: var retrievedObject = localStorage.getItem('textValue'); when I want to ...

sending data from a servlet to ajax

Implementing a star-based voting system involves sending an ajax request to update the database through a servlet when a user casts their vote. This is the ajax code used: $.ajax({ type:'GET', contentType: "charset=utf- ...

Steps for redirecting to an external URL with response data following an HTTP POST request:

this.http.post<any>('https://api.mysite.com/sources', [..body], [...header]) .subscribe(async res => { const someData = res.data; const url = res.url; window.location.href = url }) After redirecting to the specified UR ...

What is the best choice for the back-end database system?

Currently, I am in the process of developing an iPhone application that will rely on cloud-based database storage. As I explore my options, I am seeking advice on which solution would be the best fit for my needs. Here are the key requirements: The ab ...

Utilize MaterialUI Grid to define custom styles for the ::after pseudo-element

I came across a helpful article on Stack Overflow about Flex-box and how to align the last row to the grid. I'm interested in implementing it in my project: .grid::after { content: ""; flex: auto; } However, I'm not sure how to inc ...

What are the steps for expanding the functionality of the sails.js library?

I am interested in expanding sailsjs to incorporate a feature similar to rails strong params, like this: req.params.limit(["email", "password", "password_confirmation"]) I have already created an addon for this, but I want it to automatically connect to ...

Is there a method to add a number to the end of an array without relying on the push function?

I'm currently attempting to add a number to the end of an array without using the push function. As it stands, my array is returning [1, 2, 3, 10], but when I check its length it shows 8. It seems like it's counting the array elements and the se ...

How can I make rows appear dynamically when the user clicks a button?

I am trying to add rows dynamically when the user clicks on a button. I have created a script for this purpose, but unfortunately, it is not working as expected. Can someone please assist me with fixing it? <script> var i; i = 2; function AddR ...

Generating interactive form input fields using flexible ng-model functionality

I have a JSON object in my controller and I would like to dynamically generate input fields using ng-repeat. $scope.keyValuePairs = [ {id:""}, {type:""}, {brand:""}, {category:""}, {subCategory:""}, {division:""} ]; And in the tem ...

Show a pop-up window when a button is clicked, just before the page redirects

Is there a way to display a popup message before redirecting to another page when clicking on a button? Here's the scenario: <a href="addorder.php?id=<? echo $row01['id']; ?>" ><button id="myButton" class="btn btn-primary btn ...