This guide will give you detailed information about how to migrate from contentstack-javascript to DataSync.
Some important points before we move in:
// In `contentstack-javascript`, you need to call
Stack.ContentType('')
// In DataSync SDK, you need to call
Stack.contentType('')// In contentstack-javascript, you need to call
Stack.ContentType('') .Query() .ascending(fieldName: string)
// In DataSync SDK, you need to call
Stack.contentType('') .entries() .ascending(fieldName: string)
//In `contentstack-javascript`, you need to call
Stack.ContentType('')
.Query()
.descending(fieldName: string)
//In DataSync SDK, you need to call
Stack.contentType('')
.entries()
.descending(fieldName: string)Stack.ContentType('')
.Query()
.where(field, value)Stack.contentType('')
.entries()
.where(expression)
// Expression here is similar to: <a href="https://docs.mongodb.com/manual/reference/operator/query/where/" target="_blank">https://docs.mongodb.com/manual/reference/operator/query/where/</a>const Query1 = Stack.ContentType('blog').Query().where('title', 'Demo')
const Query2 = Stack.ContentType('blog').Query().lessThan('comments', 10)
Stack.ContentType('')
.entries()
.and(Query1, Query2)
.find()Stack.ContentType('blog')
.entries()
.and([
{
$where: () => {
this.title = 'Demo'
},
},
{
comments: {
$lt: 10
}
}
])
.find()const Query1 = Stack.ContentType('blog').Query().where('title', 'Demo')
const Query2 = Stack.ContentType('blog').Query().lessThan('comments', 10)
Stack.ContentType('')
.entries()
.or(Query1, Query2)
.find()Stack.ContentType('blog')
.entries()
.or([
{
$where: () => {
this.title = 'Demo'
},
},
{
comments: {
$lt: 10
}
}
])
.find()// .only with field uid
.only('title')
// .only with field uid
only('BASE','title')
// .only with field uids(array)
.only(['title','description'])
// .only with reference_field_uid and field uid
.includeReference('category').only('category','title')
// .only with reference_field_uid and field uids(array)
.includeReference('category').only('category', ['title', 'description'])/**
* Currently, projections do not work on reference fields.
* It's proposed to be added in v1.1.x release
*/
Stack.contentType('')
.entries()
.include('categories')
.only(['title', 'categories'])// .except with field uid
.except('title')
// .except with field uid
except('BASE','title')
// .except with field uids(array)
.except(['title','description'])
// .except with reference_field_uid and field uid
.includeReference('category').except('category','title')
// .except with reference_field_uid and field uids(array)
.includeReference('category').except('category', ['title', 'description'])/**
* Currently, projections do not work on reference fields.
* It's proposed to be added in v1.1.x release
*/
Stack.contentType('')
.entries()
.include('categories')
.except(['title', 'categories'])Stack.ContentType('')
.Query()
.includeReferences([''])Stack.contentType('')
.entries()
.include([''])Stack.ContentType('')
.Query()
.includeReferences('reference')
.query({
$and: [
{
description: 'This is a special blog'
},
{
reference: {
$in_query: {
title: 'Expectation'
}
}
}
]
})Stack.ContentType('')
.entries()
.include('reference')
.query({
description: 'This is a special blog'
})
.queryReferences({
reference.title: 'Expectation'
})The following methods have not been changed in DataSync: