• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Resource-like factory for MongoLab based on $http and working with promises

Build Status devDependency Status

Promise-aware MongoLab $resource-like adapter for AngularJS

Introduction

This repository hosts a Mongolab $resource-like adapter for AngularJS. It is based on $http and is working with promises.

This is a small wrapper around the AngularJS $http that makes setting up and working with MongoLab easy. It has an interface very similar to $resource but works with promises. It significantly reduces the amount of boilerplate code one needs to write when interacting with MongoDB / MongoLab (especially around URLs handling, resource objects creation and identifiers handling).

Examples

To see it in action check this plunker: (http://plnkr.co/edit/Bb8GSA?p=preview).

Usage instructions

Firstly you need to include both AngularJS and the angular-mongolab.js script [https://github.com/pkozlowski-opensource/angularjs-mongolab/blob/master/src/angular-mongolab.js](from this repository).

Then, you need to configure 2 parameters:

  • MongoLab key (API_KEY)
  • database name (DB_NAME)

Configuration parameters needs to be specified in a constant MONGOLAB_CONFIG on an application's module:

var app = angular.module('app', ['mongolabResourceHttp']);

app.constant('MONGOLAB_CONFIG',{API_KEY:'your key goes here', DB_NAME:'angularjs'});

Then, creating new resources is very, very easy and boils down to calling $mongolabResource with a MongoDB collection name:

app.factory('Project', function ($mongolabResourceHttp) {
    return $mongolabResourceHttp('projects');
});

As soon as the above is done you are ready to inject and use a freshly created resource in your services and controllers:

app.controller('AppController', function ($scope, Project) {
  Project.all().then(function(projects){
    $scope.projects = projects;
  });
});

Documentation

Since this $resource-like implementation is based on $http and returns a promise. Each resource created with the $mongolabResourceHttp will be equipped with the following methods:

  • on the class level:
    • Resource.all([options])
    • Resource.query(criteriaObject,[options])
    • Resource.getById(idString)
    • Resource.getByIds(idsArray)
    • Resource.count(criteriaObject)
    • Resource.distinct(fieldName, criteriaObject)
  • on an instance level:
    • resource.$id()
    • resource.$save()
    • resource.$update()
    • resource.$saveOrUpdate()
    • resource.$remove()

Resource all and query supported options:

  • sort: ex.: Resource.all({ sort: {priority: 1} });
  • limit: ex.: Resource.all({ limit: 10 });
  • fields: 1 - includes a field, 0 - excludes a field, ex.: Resource.all({ fields: {name: 1, notes: 0} });
  • skip: ex.: Resource.all({ skip: 10 });

Contributting

New contributions are always welcomed. Just open a pull request making sure that it contains tests, doc updates. Checked if the Travis-CI build is alright.

Contributtors

https://github.com/pkozlowski-opensource/angularjs-mongolab/graphs/contributors

More Repositories

1

ng2-play

A minimal Angular2 playground using TypeScript and SystemJS loader
JavaScript
536
star
2

angularjs-mongolab-depreciated

Mongolab $resource adapter for angular.js
JavaScript
61
star
3

ng2-webpack-play

A minimal Angular2 playground using TypeScript and WebPack
44
star
4

ng2-play.ts

A minimal Angular2 playground using TypeScript
40
star
5

directives-workshop

JavaScript
39
star
6

angularjs-AwesomeChartJS

A directive for angular.js wrapping AwesomeChartJS
JavaScript
13
star
7

ng2-bs

Experiments with Angular2 directives for Bootstrap
TypeScript
8
star
8

tdd-js-ng

JavaScript
6
star
9

gulp4-poc

JavaScript
5
star
10

ng2-ref-app

JavaScript
4
star
11

clientify

Process npm's node_modules folder to create a folder structure that makes sense for client-side development
JavaScript
3
star
12

gulp-karma-sauce

Shell
2
star
13

js-with-ng-intro

JavaScript
2
star
14

batmobile.js

A super-powered car built on JS from the future
JavaScript
2
star
15

angular2-web-components

Various experiments with Angular2 and web components integration
2
star
16

ng-europe-2014

JavaScript
2
star
17

ng-green-table

TypeScript
1
star
18

ng2-internals

1
star
19

ng2-es5-play

HTML
1
star
20

sandbox

Playground for trying out git commands / workflows - nothing interesting in here
1
star
21

adapton-like

TypeScript
1
star
22

js-with-ng-advanced

JavaScript
1
star
23

travis-play

A repo to test grunt + testacular + jasmine + AngularJS with Travis
JavaScript
1
star
24

cjs-packaging

JavaScript
1
star
25

superintendent

Orchestrating tasks expressed as function - playing with ideas for Gulp
JavaScript
1
star
26

ogm-neo4j-doc

Documentation and code snipets for work on Neo4j adapter for Hibernate OGM
1
star
27

ng-repro

HTML
1
star
28

jasmine-presentation

Materials and code samples for Jasmine testing framework presentation
JavaScript
1
star
29

generator-pk-node

yo generator for my node.js modules (gulp + travis)
JavaScript
1
star