HootShe AngularJS
An AngularJS module to use HootShe
Installation
Browser
<script src="angular.js"></script>
<script src="angular-resource.js"></script>
<script src="hootshe-angularjs.js"></script>
<!-- HootShe CDN -->
<script src="https://cdn.jsdelivr.net/gh/hootshe/hootshe-angularjs@1.0.0/dist/hootshe-angularjs.min.js"></script>
Bower
$ bower install hootshe-angularjs
Usage
Step 1. App Module
angular.module('MyApp', ['HootShe'])
.config(function($provide) {
$provide.constant('HootSheBackendURL', 'https://example.hootshe.com/v1');
});
Step 2. Controller
angular.module('MyApp')
.controller('MyCtrl', function($scope, HootShe) {
// You can now use HootShe...
});
GET
var request = {
"collection":"collection_name",
"limit" : 12,
"offset" : 0
}
HootShe.query(request, function(result) {
//do something...
},function(error) {
console.log(error);
});
GET by ID
HootShe.get({collection:'mycollection', id:'707f1f77bcf86cd799439077'}, function(result) {
//do something...
},function(error) {
console.log(error);
});
QUERY
var request = {
"collection":"collection_name",
"datas.age" : 50,
"title$like" : "Owls",
"limit" : 10,
"offset" : 0,
"sort" : "+title",
"display" : "title+datas.age"
}
HootShe.query(request, function(result) {
//do something...
},function(error) {
console.log(error);
});
GEO QUERY
var request = {
"collection":"collection_name",
"datas.age" : 50,
"title$like" : "Owls",
"lat" : 32.448629,
"lng" : -121.143933,
"distance" : 99,
"limit" : 12,
"offset" : 0,
"display" : "title+location"
}
HootShe.query(request, function(result) {
//do something...
},function(error) {
console.log(error);
});
POST
var thing = {
"grants" : ['public'],
"owner" : "907f1f77bcf86cd799439099"
"title" : "Hoot",
"description" : "A low, wavering musical sound which is the typical call of many kinds of owl.",
"datas" : {
"grants" : ['user'],
"age" : 33,
"array_of_string" : ['Hoot','owl','call']
}
"other_datas" : {
"grants" : ['admin'],
"age" : 33,
"something" : "Only admin's group can see this"
},
"location" : {
"grants" : ['user'],
"coordinates" : [-121.143933,32.448629]
}
}
HootShe.save({collection:'collection_name'}, thing, function(result) {
//do something...
},function(error) {
console.log(error);
});
PUT
var thing = {
"_id" : "707f1f77bcf86cd799439077"
"grants" : ['public'],
"owner" : "907f1f77bcf86cd799439099"
"title" : "Owl hooting",
"description" : "Owls hooted, the new moon Rose",
"datas" : {
"grants" : ['user'],
"age" : 33,
"array_of_string" : ['Hoot','owl', 'new', 'moon', 'Rose']
}
"other_datas" : {
"grants" : ['admin'],
"age" : 33,
"something" : "Only admin's group can see this"
},
"location" : {
"grants" : ['user'],
"coordinates" : [-121.143933,32.448629]
}
}
HootShe.update({collection:'collection_name', id:thing._id}, thing, function(result) {
//do something...
},function(error) {
console.log(error);
});
DELETE
HootShe.delete({collection:'collection_name', id:'707f1f77bcf86cd799439077'}, function(result) {
//do something...
},function(error) {
console.log(error);
});
MongoDB Command
angular.module('MyApp')
.controller('MyCtrl', function($scope, MongoDB) {
var command = {
find: "Owls",
filter: { rating: { $gte: 9 }, city: "Paris" },
projection: { name: 1, rating: 1, address: 1 },
sort: { name: 1 },
limit: 5
}
MongoDB.runCommand({},command,function(result) {
//do something...
},function(error) {
console.log(error);
});
});