@@ -14,67 +14,77 @@ MongoDB adapter for [js-data](http://www.js-data.io/).
14
14
## Table of contents
15
15
16
16
* [ Quick start] ( #quick-start )
17
- * [ Documentation] ( #documentation )
18
- * [ API Reference] ( #api-reference )
19
- * [ Support] ( #support )
17
+ * [ Guides and Tutorials] ( #guides-and-tutorials )
18
+ * [ API Reference Docs] ( #api-reference-docs )
20
19
* [ Community] ( #community )
20
+ * [ Support] ( #support )
21
21
* [ Contributing] ( #contributing )
22
22
* [ License] ( #license )
23
23
24
24
## Quick Start
25
- ` npm install --save js-data js-data-mongodb ` .
25
+ ` npm install --save js-data js-data-mongodb mongodb bson ` .
26
26
27
27
``` js
28
- var JSData = require (' js-data' );
29
- var DSMongoDBAdapter = require (' js-data-mongodb' );
30
-
31
- var store = new JSData.DS ();
32
- var adapter = new DSMongoDBAdapter (' mongodb://localhost:27017' );
28
+ // Use Container instead of DataStore on the server
29
+ import {Container } from ' js-data'
30
+ import MongoDBAdapter from ' js-data-mongodb'
31
+
32
+ // Create a store to hold your Mappers
33
+ const store = new Container ({
34
+ mapperDefaults: {
35
+ // MongoDB uses "_id" as the primary key
36
+ idAttribute: ' _id'
37
+ }
38
+ })
39
+
40
+ // Create an instance of MongoDBAdapter with default settings
41
+ const adapter = new MongoDBAdapter ()
42
+
43
+ // Mappers in "store" will use the MongoDB adapter by default
44
+ store .registerAdapter (' mongodb' , adapter, { default: true })
45
+
46
+ // Create a Mapper that maps to a "user" collection
47
+ store .defineMapper (' user' )
48
+ ```
33
49
34
- // "store" will now use the MongoDB adapter for all async operations
35
- store .registerAdapter (' mongodb' , adapter, { default: true });
50
+ ``` js
51
+ async function findAllAdminUsers () {
52
+ // Find all users where "user.role" == "admin"
53
+ return await store .findAll (' user' , {
54
+ role: ' admin'
55
+ })
56
+ }
57
+ ```
36
58
37
- var User = store .defineResource ({
38
- // Why couldn't Mongo just use "id"?
39
- idAttribute: ' _id' ,
59
+ ## Guides and Tutorials
40
60
41
- // map this resource to a collection, default is Resource#name
42
- table: ' users'
43
- });
44
- ```
61
+ [ Get started at http://js-data.io ] ( http://js-data.io )
45
62
46
- ### Documentation
47
- - [ Getting Started with js-data] ( http://www.js-data.io/docs/home )
48
- - [ js-data-mongodb] ( http://www.js-data.io/docs/js-data-mongodb )
49
- - [ CHANGELOG.md] ( https://github.com/js-data/js-data-mongodb/blob/master/CHANGELOG.md )
63
+ ## API Reference Docs
50
64
51
- ## API Reference
52
- - [ js-data-mongodb] ( http://api.js-data.io/js-data-mongodb/ )
65
+ [ Visit http://api.js-data.io ] ( http://api.js-data.io ) .
53
66
54
- ## Support
67
+ ## Community
55
68
56
- Support questions are handled via [ StackOverflow] [ so ] , [ Slack] [ sl_l ] , and the
57
- [ Mailing List] [ ml ] . Ask your questions there.
69
+ [ Explore the Community] ( http://js-data.io/docs/community ) .
58
70
59
- When submitting bug reports on GitHub, please include as much detail as possible
60
- to make debugging quick and easy.
71
+ ## Support
61
72
62
- ## Community
63
- - [ StackOverflow Channel] [ so ]
64
- - [ Slack Chat] [ sl_l ] [ ![ Slack Status] [ sl_b ]] [ sl_l ]
65
- - [ Announcements] ( http://www.js-data.io/blog )
66
- - [ Mailing List] ( ml )
67
- - [ Issue Tracker] ( https://github.com/js-data/js-data-mongodb/issues )
73
+ [ Find out how to Get Support] ( http://js-data.io/docs/support ) .
68
74
69
75
## Contributing
70
76
71
- See [ CONTRIBUTING.md ] ( https ://github.com/ js-data/js-data-mongodb/blob/master/CONTRIBUTING.md ) .
77
+ [ Read the Contributing Guide ] ( http ://js-data.io/docs/contributing ) .
72
78
73
79
## License
74
80
75
81
The MIT License (MIT)
76
82
77
- See [ LICENSE] ( https://github.com/js-data/js-data-mongodb/blob/master/LICENSE ) .
83
+ Copyright (c) 2014-2016 js-data-mongodb project authors
84
+
85
+ * [ LICENSE] ( https://github.com/js-data/js-data-mongodb/blob/master/LICENSE )
86
+ * [ AUTHORS] ( https://github.com/js-data/js-data-mongodb/blob/master/AUTHORS )
87
+ * [ CONTRIBUTORS] ( https://github.com/js-data/js-data-mongodb/blob/master/CONTRIBUTORS )
78
88
79
89
[ sl_b ] : http://slack.js-data.io/badge.svg
80
90
[ sl_l ] : http://slack.js-data.io
@@ -88,6 +98,3 @@ See [LICENSE](https://github.com/js-data/js-data-mongodb/blob/master/LICENSE).
88
98
[ cov_l ] : https://coveralls.io/github/js-data/js-data-mongodb?branch=master
89
99
[ cod_b ] : https://img.shields.io/codacy/1f45ede49dfb4bdea68f46ca55631968.svg
90
100
[ cod_l ] : https://www.codacy.com/app/jasondobry/js-data-mongodb/dashboard
91
-
92
- [ ml ] : https://groups.io/org/groupsio/jsdata
93
- [ so ] : http://stackoverflow.com/questions/tagged/jsdata
0 commit comments