Skip to main content

Initialize the SDK

🎯 SDK Comparison Overview

SDK TypePlatformObjectFeaturesRecommended ScenariosDocumentation Link
Mini Program SDKWeChat Mini ProgramCollectionBuilt-in SDK, no installation requiredDirect database collection operations in Mini ProgramsMini Program SDK Initialization
Web SDKWeb BrowsersData Models, CollectionsLightweight, supports modern browsersWeb Applications, H5 PagesWeb SDK Initialization
Node.js SDKNode.js EnvironmentData Models, CollectionsServer-side permissions, full functionalityCloud Functions, Background ServicesNode.js SDK Initialization
HTTP APIAny PlatformRESTful InterfacesCross-Language SupportThird-Party System IntegrationHTTP Documentation

Initialize based on the selected SDK

wxCloud

wx.cloud is a built-in feature of the Mini Program and does not require installation.

Initialization

Configure initialization in the app.js file of the Mini Program:

wx.cloud.init({
env: 'your-env-id', // Replace with your environment ID
traceUser: true,
})

Parameter Description

FieldData TypeRequiredDefault ValueDescription
envstring✅ Yes-Environment ID, specifies which environment's cloud resources to access
traceUserboolean❌ NotrueWhether to log user visits to user management for viewing in the console

Collection Operations Example

wx.cloud.init({
env: 'your-env-id', // Replace with your environment ID
traceUser: true,
})

// Get the database instance (for collection operations)
const db = wx.cloud.database()

// Query a single record by document ID
const result = await db.collection('todos')
.doc('docId')
.get()

console.log('Query result:', result.data)

🚀 Next Steps

Next, based on the database instance or data model instance provided by the SDK, perform data operations.