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
4. **UI Design** (Recommended): Read the `ui-design` skill for better UI/UX design guidelines
234
235
5. **Quick SDK reference**:
@@ -276,6 +277,7 @@ Prefer long-term memory when available: write the scenarios and working rules th
276
277
277
278
**Web Projects:**
278
279
- NoSQL Database: Refer to the `no-sql-web-sdk` skill
280
+
- For CloudBase Web SDK `db.collection(...).add(...)`, read the created document ID from `result._id`, not `result.id`, `result.data.id`, or `insertedId`
279
281
- MySQL Relational Database: Refer to the `relational-database-web` skill (Web) and `relational-database-tool` skill (Management)
Copy file name to clipboardExpand all lines: config/source/skills/no-sql-web-sdk/SKILL.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,7 @@ Keep local `references/...` paths for files that ship with the current skill dir
47
47
- Using `wx.cloud.database()` or Node SDK patterns in browser code.
48
48
- Initializing CloudBase lazily with dynamic imports instead of a shared synchronous app instance.
49
49
- Treating security rules as result filters rather than request validators.
50
+
- Misreading the return shape of `db.collection(...).add(...)`. In the CloudBase Web SDK, the created document ID is exposed at top-level `result._id`, not `result.id`, `result.data.id`, or `result.insertedId`.
50
51
- For CMS-style collections that need **app-level admin users** to edit/delete all records while editors can only edit/delete their own records, do not oversimplify the rule to `READONLY`. A validated pattern is a `CUSTOM` rule that reads role from `user_roles` by `auth.uid` and combines it with `doc.authorId == auth.uid`, while frontend writes can stay on `.doc(id).update()` / `.doc(id).remove()`.
51
52
- Forgetting pagination or indexes for larger collections.
52
53
@@ -119,6 +120,10 @@ Important rules:
119
120
- Database errors must become readable UI or application errors, not silent failures.
120
121
- For writes, do not treat a resolved promise as success by default. Check write result fields such as `updated` / `deleted` or surfaced `code` / `message`.
121
122
123
+
5.**Persist IDs from create operations correctly**
124
+
- For Web SDK `.add(...)`, the newly created document ID is `result._id`.
125
+
- Do not look for the ID under `result.id`, `result.data`, or other driver-specific fields.
126
+
122
127
## Quick examples
123
128
124
129
### Simple query
@@ -129,6 +134,18 @@ const result = await db.collection("todos")
0 commit comments