May 20, 2021 WeChat Mini Program Development Document
1. Parameters
2. Returns a value
3. API description
4. The sample code
5. Parameters
6. Returns a value
7. API description
8. The sample code
9. Parameters
10. Returns a value
11. API description
12. The sample code
13. Parameters
14. Returns a value
15. API description
16. The sample code
17. Parameters
18. Returns a value
19. API description
20. The sample code
21. Parameters
22. Returns a value
23. API description
24. The sample code
25. Parameters
26. Returns a value
27. API description
28. The sample code
29. Parameters
30. Returns a value
31. API description
32. The sample code
33. Parameters
34. Returns a value
35. API description
36. The sample code
37. Parameters
38. Returns a value
39. API description
40. The sample code
41. Parameters
42. Returns a value
43. API description
44. The sample code
45. Parameters
46. Returns a value
47. API description
48. The sample code
49. Parameters
50. Returns a value
51. API description
52. The sample code
53. Parameters
54. Returns a value
55. API description
56. The sample code
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Given two values, return their comparison values:
[<expression1>, <expression2>]
If the first value is less than the second value, return -1 If the first value is greater than the second value, return 1 If the two values are equal, return 0
The syntax is as follows:
db.command.aggregate.cmp([<expression1>, <expression2>])
Suppose the collection price has the following records:
{ "_id": 1, "shop1": 10, "shop2": 100 }
{ "_id": 2, "shop1": 80, "shop2": 20 }
{ "_id": 3, "shop1": 50, "shop2": 50 }
Find a price comparison for each item in shop1 and shop2.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
compare: $.cmp(['$shop1', '$shop2']))
})
.end()
The results are as follows:
{ "_id": 1, "compare": -1 }
{ "_id": 2, "compare": 1 }
{ "_id": 3, "compare": 0 }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values and return true if equal, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.eq([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
A record with value equal to 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.eq(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": false }
{ "_id": 2, "matched": false }
{ "_id": 3, "matched": true }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values, and return true if the former is greater than the latter, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.gt([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Determines whether value is greater than 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.gt(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": false }
{ "_id": 2, "matched": true }
{ "_id": 3, "matched": false }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values, and if the former is greater than or equal to the latter, true is returned, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.gte([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Determines whether value is greater than or equal to 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.gte(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": false }
{ "_id": 2, "matched": true }
{ "_id": 3, "matched": true }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values, and return true if the former is less than the latter, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.lt([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Determines whether value is less than 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.lt(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": true }
{ "_id": 2, "matched": false }
{ "_id": 3, "matched": false }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values, and return true if the former is less than or equal to the latter, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.lte([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Determines whether value is less than 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.lte(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": true }
{ "_id": 2, "matched": false }
{ "_id": 3, "matched": true }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values and return true if they are not equal, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.neq([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
A record that finds value is not equal to 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.neq(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": true }
{ "_id": 2, "matched": true }
{ "_id": 3, "matched": false }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Given two values, return their comparison values:
[<expression1>, <expression2>]
If the first value is less than the second value, return -1 If the first value is greater than the second value, return 1 If the two values are equal, return 0
The syntax is as follows:
db.command.aggregate.cmp([<expression1>, <expression2>])
Suppose the collection price has the following records:
{ "_id": 1, "shop1": 10, "shop2": 100 }
{ "_id": 2, "shop1": 80, "shop2": 20 }
{ "_id": 3, "shop1": 50, "shop2": 50 }
Find a price comparison for each item in shop1 and shop2.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
compare: $.cmp(['$shop1', '$shop2']))
})
.end()
The results are as follows:
{ "_id": 1, "compare": -1 }
{ "_id": 2, "compare": 1 }
{ "_id": 3, "compare": 0 }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values and return true if equal, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.eq([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
A record with value equal to 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.eq(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": false }
{ "_id": 2, "matched": false }
{ "_id": 3, "matched": true }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values, and return true if the former is greater than the latter, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.gt([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Determines whether value is greater than 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.gt(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": false }
{ "_id": 2, "matched": true }
{ "_id": 3, "matched": false }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values, and if the former is greater than or equal to the latter, true is returned, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.gte([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Determines whether value is greater than or equal to 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.gte(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": false }
{ "_id": 2, "matched": true }
{ "_id": 3, "matched": true }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values, and return true if the former is less than the latter, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.lt([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Determines whether value is less than 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.lt(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": true }
{ "_id": 2, "matched": false }
{ "_id": 3, "matched": false }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values, and return true if the former is less than or equal to the latter, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.lte([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Determines whether value is less than 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.lte(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": true }
{ "_id": 2, "matched": false }
{ "_id": 3, "matched": true }
Support: Small program 2.7.4, cloud function 0.8.1, Web
The aggregate operator. Match two values and return true if they are not equal, otherwise false is returned.
[<value1>, <value2>]
The syntax is as follows:
db.command.aggregate.neq([<value1>, <value2>])
Suppose the collection price has the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
A record that finds value is not equal to 50.
const $ = db.command.aggregate
db.collection('price').aggregate()
.project({
matched: $.neq(['$value', 50])
})
.end()
The results are as follows:
{ "_id": 1, "matched": true }
{ "_id": 2, "matched": true }
{ "_id": 3, "matched": false }