Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 57 lines (36 sloc) 1.592 kB
958ae58 @garrensmith update docs
authored
1 ---
2 layout: default
3 title: Queries
4 ---
5
99a2aea @garrensmith more docs and load models from directory
authored
6 Querying
7 ========
958ae58 @garrensmith update docs
authored
8
99a2aea @garrensmith more docs and load models from directory
authored
9 LazyBoy supports multiple ways of finding a specified document or documents for model.
958ae58 @garrensmith update docs
authored
10
99a2aea @garrensmith more docs and load models from directory
authored
11 ## Find All
958ae58 @garrensmith update docs
authored
12
99a2aea @garrensmith more docs and load models from directory
authored
13 Find All will return all documents for a specified model. It will return an array with all the documents contained inside.
14
15 User.all(function (err, users) {
16 // all users
17 });
e85165d @garrensmith start of the docs
authored
18
19 ## Find by Id
20
99a2aea @garrensmith more docs and load models from directory
authored
21 Finding by the Id will return only one document with the specified document or null if no documents match that Id.
22
23 Blog.find("12345", function (err, blog_post) {
24 // do something with the blog post
25 });
26
e85165d @garrensmith start of the docs
authored
27 ## Find by property
28
99a2aea @garrensmith more docs and load models from directory
authored
29 LazyBoy creates some generic views to be used with each model. These can be accessed via the `.where` property on each model.
30 It takes two arguments the propery to search by and the value of the propery to group by. This method always returns an array of the results.
31
32 Album.where("band","coldplay", function (err, albums) {
33 albums.forEach(....
34 });
35
958ae58 @garrensmith update docs
authored
36 ## Custom views
99a2aea @garrensmith more docs and load models from directory
authored
37
38 It is also possible to create custom views for a specific require of a model. This is done when defining a model.
39
40 var Album = Model.define("Album",{band: String, title: String, rating: Number});
41
42 Album.addView('BestIncubusAlbums',{
43 map: function (doc) {
44 if (doc.model_type === 'Album' && doc.band === 'Incubus' && doc.rating === 5) {
45 emit(null,doc);
46 }
47 }
48 });
49
50 Then to query that view
51
52 Album.view('BestIncubusAlbums', function (err, albums) {
53
54
55 });
56
Something went wrong with that request. Please try again.