You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|url|string|mongodb://localhost:27017 |**Optional.** The MongoDB connection URI|
22
22
|limit|number|100|**Optional.** Caps the total no of objects returned in a single call|
23
23
|skip|number|0|**Optional.** Number of objects skipped before the result is returned|
24
24
| indexes | object |**[see config below](https://github.com/contentstack/datasync-content-store-mongodb#detailed-configs)**|**Optional.** Option to create db indexes via configuration|
25
25
|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|
26
26
|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)|
27
28
28
-
### Detailed configs
29
+
### Config Overview
29
30
30
-
By default, this module uses the following internal configuration.
31
+
Here's an overview of the SDK's configurable properties
// 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
+
})
73
104
```
105
+
> Important: You need to call .connect(), to initiate SDK queries!
74
106
75
-
To initialize the SDK, you'd need to perform the following steps
76
-
77
-
1. Initialize stack instance.
78
-
```js
79
-
constStack=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
91
108
92
109
### Querying
93
-
94
110
- Notes
95
111
- 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.
97
113
- 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.
// 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)
137
146
```
138
147
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)
159
164
```
160
165
161
166
## Advanced Queries
@@ -169,7 +174,7 @@ In order to learn more about advance queries please refer the API documentation,
169
174
170
175
### Support and Feature requests
171
176
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.
173
178
174
179
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!
0 commit comments