forked from travis4all/baucis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjQuery.js
58 lines (54 loc) · 1.37 KB
/
jQuery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Baucis examples using jQuery
// ============================
(function () {
// Fetch an entity by ID
$.getJSON('/api/vegetables/4f4028e6e5139bf4e472cca1', function (data) {
console.log('Fetch an entity:');
console.log(data);
});
// POST a new entity to the vegetables collection
$.ajax({
type: 'POST',
dataType: 'json',
contentType : 'application/json',
url: '/api/vegetables',
data: JSON.stringify({
name: 'carrot',
color: 'orange'
})
}).done(function (vegetable) {
// The new document that was just created
console.dir(vegetable);
});
// Requests to the collection (not its members) take standard MongoDB query parameters to filter the documents based on custom criteria.
$.ajax({
type: 'GET',
dataType: 'json',
url: '/api/vegetables',
contentType : 'application/json',
data: JSON.stringify({
limit: 2,
sort: 'color',
conditions: {
color: 'red',
'nutrition.sodium': { $lte: 10 }
},
populate: [
{
path: 'child1',
select: ['fieldA', 'fieldB'],
match: {
'foo': { $gte: 7 }
},
options: { limit: 1 }
},
{
path: 'child2',
select: '-_id color nutrition'
}
]
})
}).done(function (vegetables) {
console.dir(vegetables);
});
})();