WeChat Miniprogram - Cloud Development - Database Error: -501007 invalid parameters | errMsg: Invalid Key Name: _openid

Translation Notice
This article was machine-translated using DeepSeek-R1.

  • Original Version: Authored in Chinese by myself
  • Accuracy Advisory: Potential discrepancies may exist between translations
  • Precedence: The Chinese text shall prevail in case of ambiguity
  • Feedback: Technical suggestions regarding translation quality are welcomed

Error:

1
-501007 invalid parameters | errMsg: Invalid Key Name: _openid

Cause:

Cannot manually set _openid field, it’s automatically populated by the cloud server based on user’s OpenID

Solution:

Remove openID field from data object

Incorrect Code

1
2
3
4
5
6
7
8
wx.cloud.database().collection('people').add({
  data: {
    '_openid': openID,
    'name': nickName,
    'avatarUrl': avatarUrl,
    'score': score
  }
})

Corrected Code

1
2
3
4
5
6
7
wx.cloud.database().collection('people').add({
  data: {
    'name': nickName,
    'avatarUrl': avatarUrl,
    'score': score
  }
})
Built with Hugo
Theme Stack designed by Jimmy