wx.cloud.database().command
时间: 2024-01-16 11:04:00 浏览: 83
javascript获取wx.config内部字段解决微信
wx.cloud.database().command is a method in the WeChat Mini Program API that allows developers to execute commands directly on the database. This method can be used to perform operations such as aggregate, distinct, and geoNear.
Here is an example of using wx.cloud.database().command to perform an aggregate operation:
```
const db = wx.cloud.database()
const _ = db.command
db.collection('orders').aggregate()
.group({
_id: '$status',
total: _.sum('$amount')
})
.end()
.then(res => {
console.log(res)
})
```
In this example, we are using wx.cloud.database().command to perform a group aggregation on the 'orders' collection. We group the orders by their 'status' field and calculate the total amount using _.sum('$amount'). The result of the aggregation is then logged to the console.
阅读全文