Skip to main content
skill CX Codex

cloudbase-document-database-in-wechat-miniprogram — Claude Code skill

A skill that steers the agent through CloudBase document database work in a WeChat Mini Program: queries, pagination, aggregation, geolocation.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add TencentCloudBase/skills --skill cloudbase-document-database-in-wechat-miniprogram -a claude-code
Open on GitHub

What cloudbase-document-database-in-wechat-miniprogram does

The skill activates when Mini Program code talks to the database through wx.cloud.database(). It hands the agent initialization rules, ownership handling, and a routing table for CRUD, complex queries, pagination, aggregation, geolocation and security rules — each topic in its own reference file next to SKILL.md.

An activation contract spells out when to use it, what to read before writing code, and what it is not for. Browser code with @cloudbase/js-sdk, server-side access, cloud functions and MySQL are explicitly out of scope. There is also a gotcha list: pasting Web SDK snippets into Mini Program pages, and writing _openid by hand on create or update.

That last point matters. _openid is system-managed for SDK writes, so it should not appear in .add(), .set() or .update() payloads. When a collection rule checks ownership, the query shape has to match that rule model — permission errors usually mean the rule and the query disagree, not that the user is signed out. For privileged global access the skill points you to backend flows instead of exposing that path in client code.

What it helps with

  • run collection CRUD from a Mini Program page
  • build a filtered query with pagination
  • compute an aggregation over documents
  • find records near a map point
  • debug a collection rule that rejects a query

Example prompts for the agent

  • show me how to fetch unfinished todos with pagination using wx.cloud.database()
  • I need an aggregation query over the orders collection in my Mini Program
  • why does this query fail with a permission error when the collection rule checks _openid

How to install cloudbase-document-database-in-wechat-miniprogram

1Skills CLI (Vercel)

npx skills add TencentCloudBase/skills --skill cloudbase-document-database-in-wechat-miniprogram -a claude-code

2Manually: put the files in place

~/.claude/skills/cloudbase-document-database-in-wechat-miniprogram/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/cloudbase-document-database-in-wechat-miniprogram/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about cloudbase-document-database-in-wechat-miniprogram

How do I install cloudbase-document-database-in-wechat-miniprogram in Claude?

Run npx skills add TencentCloudBase/skills --skill cloudbase-document-database-in-wechat-miniprogram -a claude-code. The skill file then lives at ~/.claude/skills/cloudbase-document-database-in-wechat-miniprogram/SKILL.md.

What does this skill do?

It gives the agent rules for CloudBase document database access from a WeChat Mini Program: wx.cloud.database() setup, CRUD, complex queries, pagination, aggregation and geolocation, plus a separate pass over security rules.

Does it cover browser code or cloud functions?

No. Browser-side work with @cloudbase/js-sdk and server-side access have their own sibling CloudBase skills; this one targets Mini Program code.

Source text

SKILL.md · MIT
---
name: cloudbase-document-database-in-wechat-miniprogram
description: Use CloudBase document database WeChat MiniProgram SDK to query, create, update, and delete data. Supports complex queries, pagination, aggregation, and geolocation queries.
version: 2.36.1
license: MIT
alwaysApply: false
---

## Sibling skills (local only)

Sibling CloudBase skills ship beside this skill. Use local relative paths such as `../auth-tool-cloudbase/SKILL.md`.

If a referenced sibling skill file is missing from this environment, ask the user to install the full CloudBase plugin (or the missing skill). Do **not** HTTP-fetch remote skill or protocol markdown into the agent context.

# CloudBase Document Database WeChat Mini Program SDK

## Activation Contract

### Use this first when

- A WeChat Mini Program must access CloudBase document database through `wx.cloud.database()`.
- The request mentions Mini Program collection CRUD, pagination, aggregation, or geolocation queries.

### Read before writing code if

- The task is Mini Program database work but you still need to separate it from Web SDK, cloud functions, or SQL tasks.
- The request depends on built-in user identity, `_openid`, or Mini Program-side permissions.

### Then also read

- Mini Program project rules and CloudBase integration -> `../miniprogram-development/SKILL.md`
- Mini Program auth and identity flow -> `../auth-wechat-miniprogram/SKILL.md`
- Browser-side document database code -> `../cloudbase-document-database-web-sdk/SKILL.md`

### Do NOT use for

- Browser/Web code using `@cloudbase/js-sdk`.
- Server-side or cloud-function database access.
- MySQL / relational database work.

### Common mistakes / gotchas

- Copying Web SDK code into Mini Program pages.
- Manually writing `_openid` during create or update operations.
- Assuming built-in Mini Program identity means security rules can be ignored.
- Mixing collection CRUD and backend-wide admin workflows in the same client path.

### Minimal checklist

- Confirm the caller is a Mini Program page/component or Mini Program-side logic.
- Initialize `wx.cloud` correctly before database calls.
- Verify whether the collection rules rely on `auth.openid` / `_openid`.
- Read the specific companion reference file for the operation you need.

## Overview

This skill covers **Mini Program-side document database access** through `wx.cloud.database()`.

Use it for:

- collection CRUD in Mini Program pages
- query composition and pagination
- aggregation
- geolocation queries

Mini Program CloudBase access comes with built-in identity, but database operations are still constrained by collection permissions and security rules.

## Canonical initialization

```javascript
const db = wx.cloud.database();
const _ = db.command;
```

To target a specific environment:

```javascript
const db = wx.cloud.database({
  env: "test"
});
```

Important notes:

- Users are authenticated through the Mini Program CloudBase context.
- In cloud functions, caller identity is available through `wxContext.OPENID`.
- In client-side collection rules, ownership checks usually use `auth.openid` / `doc._openid`.

## Quick routing

- CRUD -> `./crud-operations.md`
- Complex queries -> `./complex-queries.md`
- Pagination -> `./pagination.md`
- Aggregation -> `./aggregation.md`
- Geolocation -> `./geolocation.md`
- Security rules -> `./security-rules.md`

## Working rules for a coding agent

1. **Keep Mini Program code Mini Program-native**
   - Use `wx.cloud.database()`.
   - Do not substitute browser SDK initialization patterns.

2. **Respect ownership fields**
   - `_openid` is system-managed for SDK writes.
   - Never set or override `_openid` manually in `.add()`, `.set()`, or `.update()` payloads.

3. **Remember that security rules validate requests**
   - If a rule requires ownership conditions, the query shape must match that rule model.
   - Permission errors usually mean the rule/query relationship is wrong, not only that the user is logged out.

4. **Route admin-style operations to backend flows**
   - If the task needs privileged global access, use backend tools or functions instead of exposing that path directly in Mini Program client code.

## Quick examples

### Basic collection access

```javascript
const todos = db.collection("todos");
const result = await todos.where({ completed: false }).get();
```

### Document reference

```javascript
const todo = db.collection("todos").doc("todo-id");
const result = await todo.get();
```

## Best practices

1. Create clear collection naming conventions.
2. Use typed wrappers or model helpers in app code where possible.
3. Design rules around real ownership and sharing patterns.
4. Use pagination instead of large unbounded reads.
5. Keep admin/operations logic in backend code, not Mini Program direct access.

© TencentCloudBase · MIT · TencentCloudBase/skills

Similar skills

All skills for Data and databases →

From the same set16

miniprogram-development Guides the creation, debugging, preview, and deployment of WeChat Mini Programs. Ideal when configuring project structure, CloudBase, and wechatide CLI workflows. CX Codex +1 4,400installs auth-wechat-miniprogram A skill that tells the agent how native auth works in CloudBase WeChat Mini Programs: openid and unionid arrive in the cloud function on their own. CX Codex +1 2,200installs ui-design Makes the agent output a design specification — palette, fonts, layout — before it writes any interface code. CX Codex +1 1,800installs web-development A skill for implementing, debugging and shipping a web frontend once the product direction is settled. React, Vue, Vite, routing, browser checks. CX Codex +1 1,800installs spec-workflow Guides coding agents through phased planning in specs/: EARS requirements, system design, and tasks. Useful when acceptance criteria must be explicit before coding. CX Codex +1 1,200installs cloud-functions Guides the agent through building, deploying and debugging CloudBase Event and HTTP Functions. Useful when you need your own runtime code, not platform API calls. CX Codex +1 1,200installs ai-model-wechat A skill for calling AI models in WeChat Mini Programs through wx.cloud.extend.AI. Useful when you add text generation to a mini app and don't want to guess the call shapes. CX Codex +1 1,100installs auth-tool-cloudbase Readies CloudBase authentication before you write client code: checks providers, publishable keys and login methods. CX Codex +1 1,000installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor