Skip to content

Commit d59ba7f

Browse files
committed
v1.0.0 update. Bug fix, test case, readme.md updates
1 parent 1627b81 commit d59ba7f

23 files changed

+326
-596
lines changed

README.md

Lines changed: 123 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -14,148 +14,153 @@ Contentstack is a headless CMS with an API-first approach. It is a CMS that deve
1414

1515
### Configuration
1616

17-
|Property|Data Type|Default value|Description|
17+
|Property|Type|Default value|Description|
1818
|--|--|--|--|
1919
|dbName|string|contentstack-persistent-db|**Optional** The MongoDB database name|
20-
|collectionName|string|contents|**Optional** MongoDB database's collection name|
21-
|uri|string|mongodb://localhost:27017 |**Optional.** The MongoDB connection URI|
20+
|collection|string|contents|**Optional** MongoDB database's collection names|
21+
|url|string|mongodb://localhost:27017 |**Optional.** The MongoDB connection URI|
2222
|limit|number|100|**Optional.** Caps the total no of objects returned in a single call|
2323
|skip|number|0|**Optional.** Number of objects skipped before the result is returned|
2424
| indexes | object |**[see config below](https://github.com/contentstack/datasync-content-store-mongodb#detailed-configs)** |**Optional.** Option to create db indexes via configuration|
2525
|projections|object|**[see config below](https://github.com/contentstack/datasync-content-store-mongodb#detailed-configs)** |**Optional.** Mongodb projections. Keys provided here would be displayed/filtered out when fetching the result|
2626
|options|object|**[see config below](https://github.com/contentstack/datasync-content-store-mongodb#detailed-configs)** |**Optional.** MongoDB connection options [Ref.](http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html) for more info|
27+
|referenceDepth|number|2|**Optional** The default nested-reference-field depth that'd be considered when calling .includeReferences(). This can be overridden by passing a numerical argument to .includeReferences(4)|
2728

28-
### Detailed configs
29+
### Config Overview
2930

30-
By default, this module uses the following internal configuration.
31+
Here's an overview of the SDK's configurable properties
3132

32-
```js
33+
```ts
3334
{
34-
dbName: 'contentstack-persistent-db',
35-
collectionName: 'contents',
36-
uri: 'mongodb://localhost:27017',
37-
indexes: {
38-
published_at: -1,
39-
content_type_uid: 1,
40-
locale: 1,
41-
uid: 1
35+
contentStore: {
36+
collection: {
37+
asset: 'contents',
38+
entry: 'contents',
39+
schema: 'content_types',
40+
},
41+
dbName: 'contentstack-db',
42+
indexes: {
43+
_content_type_uid: 1,
44+
locale: 1,
45+
uid: 1,
46+
updated_at: -1,
47+
},
48+
limit: 100,
49+
locale: 'en-us',
50+
// http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html
51+
options: {
52+
autoReconnect: true,
53+
connectTimeoutMS: 15000,
54+
keepAlive: true,
55+
noDelay: true,
56+
reconnectInterval: 1000,
57+
reconnectTries: 20,
58+
useNewUrlParser: true,
59+
},
60+
projections: {
61+
_content_type_uid: 0,
62+
_id: 0,
63+
},
64+
referenceDepth: 2,
65+
skip: 0,
66+
url: 'mongodb://localhost:27017',
4267
},
43-
limit: 100,
44-
locales: [
45-
],
46-
options: {
47-
autoReconnect: true,
48-
connectTimeoutMS: 15000,
49-
keepAlive: true,
50-
noDelay: true,
51-
reconnectInterval: 1000,
52-
reconnectTries: 20,
53-
useNewUrlParser: true,
54-
},
55-
projections: {
56-
_id: 0,
57-
_version: 0,
58-
content_type_uid: 0,
59-
created_at: 0,
60-
sys_keys: 0,
61-
updated_at: 0,
62-
updated_by: 0,
63-
},
64-
skip: 0,
6568
}
6669
```
6770

68-
### Setup and Installation
69-
70-
To import the SDK in your project, use the following command:
71-
```js
72-
import { Contentstack } from 'contentstack-sync-mongodb-sdk'
71+
### Sample SDK Query
72+
73+
Here's a sample SDK query to get started.
74+
75+
Learn more on how to query using datasync-mongodb-sdk [here](https://contentstack.github.io/datasync-mongodb-sdk/).
76+
77+
```ts
78+
import { Contentstack } from 'datasync-mongodb-sdk'
79+
const Stack = Contentstack.Stack(config)
80+
81+
Stack.connect()
82+
.then(() => {
83+
return Stack.contentType('blog')
84+
.entries()
85+
.language('en-gb') // Optional. If not provided, defaults to en-us
86+
.include(['authors'])
87+
.includeCount()
88+
.includeContentType()
89+
.queryReferences({'authors.firstName': 'R.R. Martin'})
90+
.then((result) => {
91+
// Your result would be
92+
// {
93+
// entries: [...], // All entries, who's first name is R.R. Martin
94+
// content_type_uid: 'blog',
95+
// locale: 'es-es',
96+
// content_type: {...}, // Blog content type's schema
97+
// count: 3, // Total count of blog content type
98+
// }
99+
})
100+
})
101+
.catch((error) => {
102+
// handle errors..
103+
})
73104
```
105+
> Important: You need to call .connect(), to initiate SDK queries!
74106
75-
To initialize the SDK, you'd need to perform the following steps
76-
77-
1. Initialize stack instance.
78-
```js
79-
const Stack = Contentstack.Stack(config)
80-
```
81-
82-
2. Call the connect method. This method establishes a connection between the SDK and mongodb database.
83-
```js
84-
Stack.connect(dbConfig)
85-
.then(fnResolve)
86-
.catch(fnReject)
87-
```
88-
> Important: You need to call this, before running SDK queries!
89-
90-
Once you have initialized the SDK, you can start querying on the sync-utility's DB's
107+
Once you have initialized the SDK, you can start querying on mongodb
91108

92109
### Querying
93-
94110
- Notes
95111
- By default, 'content_type_uid' and 'locale' keys as part of the response.
96-
- If `.language()` is not provided, then the 1st language, provided in `config.locales` would be considered.
112+
- If `.language()` is not provided, then the 1st language, provided in `config.defaultLocale` would be considered.
97113
- If querying for a single entry/asset (using `.entry()` OR `.findOne()`), the result will be an object i.e. `{ entry: {} }`, if the entry or asset is not found, `{ entry: null }` will be returned.
98114
- Querying multiple entries, would return `{ entries: [ {...} ] }`.
99-
100-
101-
1. Query a single entry
102-
103-
```js
104-
// Sample 1. Returns the 1st entry that matches query filters
105-
Stack.contentType('blogs')
106-
.entry() // OR .asset()
107-
.language('en-us')
108-
.find()
109-
.then((result) => {
110-
// Response
111-
// result = {
112-
// entry: {
113-
// title: '' || null
114-
// },
115-
// content_type_uid: '',
116-
// locale: ''
117-
// }
118-
})
119-
.catch(reject)
120-
121-
// Sample 2. Returns the 1st entry that matches query filters
122-
Stack.contentType('blogs')
123-
.entries() // for .assets() OR .schemas() - ignore calling .contentType()
124-
.language('en-us')
125-
.findOne()
126-
.then((result) => {
127-
// Response
128-
// result = {
129-
// entry: {
130-
// title: '' || null
131-
// },
132-
// content_type_uid: '',
133-
// locale: ''
134-
// }
135-
})
136-
.catch(reject)
115+
- By default, all entry responses would include their referred assets. If `.excludeReferences()` is called, no references (including assets) would **not** be returned in the response.
116+
117+
- Query a single entry
118+
```ts
119+
// Sample 1. Returns the 1st entry that matches query filters
120+
Stack.contentType('blog')
121+
.entry() // OR .asset()
122+
.find()
123+
.then((result) => {
124+
// Response
125+
// result = {
126+
// entry: any | null,
127+
// content_type_uid: string,
128+
// locale: string,
129+
// }
130+
})
131+
.catch(reject)
132+
133+
// Sample 2. Returns the 1st entry that matches query filters
134+
Stack.contentType('blogs')
135+
.entries() // for .assets()
136+
.findOne()
137+
.then((result) => {
138+
// Response
139+
// result = {
140+
// entry: any | null,
141+
// content_type_uid: string,
142+
// locale: string,
143+
// }
144+
})
145+
.catch(reject)
137146
```
138147

139-
2. Querying a set of entries, assets or content types
140-
```js
141-
Stack.contentType('blogs')
142-
.entries() // for .assets() OR .schemas() - ignore calling .contentType()
143-
.includeCount()
144-
.find()
145-
.then((result) => {
146-
// Response
147-
// result = {
148-
// entries: [
149-
// {
150-
// title: ''
151-
// }
152-
// ],
153-
// content_type_uid: 'blogs',
154-
// locale: '',
155-
// count: 1
156-
// }
157-
})
158-
.catch(reject)
148+
- Querying a set of entries, assets or content types
149+
```ts
150+
Stack.contentType('blog')
151+
.entries() // for .assets()
152+
.includeCount()
153+
.find()
154+
.then((result) => {
155+
// Response
156+
// result = {
157+
// entry: any | null,
158+
// content_type_uid: string,
159+
// count: number,
160+
// locale: string,
161+
// }
162+
})
163+
.catch(reject)
159164
```
160165

161166
## Advanced Queries
@@ -169,7 +174,7 @@ In order to learn more about advance queries please refer the API documentation,
169174

170175
### Support and Feature requests
171176

172-
If you have any issues working with the library, please file an issue [here](https://github.com/contentstack/datasync-content-store-mongodb/issues) at Github.
177+
If you have any issues working with the library, please file an issue [here](https://github.com/contentstack/datasync-mongodb-sdk/issues) at Github.
173178

174179
You can send us an e-mail at [[email protected]](mailto:[email protected]) if you have any support or feature requests. Our support team is available 24/7 on the intercom. You can always get in touch and give us an opportunity to serve you better!
175180

dist/config.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ exports.config = {
1313
schema: 'content_types',
1414
},
1515
dbName: 'contentstack-db',
16-
// indexes: {
17-
// event_at: -1,
18-
// _content_type_uid: 1,
19-
// locale: 1,
20-
// uid: 1
21-
// },
22-
internalContentTypes: {
23-
assets: '_assets',
24-
content_types: '_content_types',
16+
indexes: {
17+
_content_type_uid: 1,
18+
locale: 1,
19+
uid: 1,
20+
updated_at: -1,
21+
},
22+
internal: {
23+
types: {
24+
assets: '_assets',
25+
content_types: '_content_types',
26+
},
2527
},
2628
limit: 100,
2729
locale: 'en-us',
@@ -38,13 +40,8 @@ exports.config = {
3840
projections: {
3941
_content_type_uid: 0,
4042
_id: 0,
41-
_synced_at: 0,
42-
_version: 0,
43-
created_at: 0,
44-
updated_at: 0,
45-
updated_by: 0,
4643
},
47-
referenceDepth: 20,
44+
referenceDepth: 2,
4845
skip: 0,
4946
uri: 'mongodb://localhost:27017',
5047
},

0 commit comments

Comments
 (0)