May 20, 2021 WeChat Mini Program Development Document
Support: small programs, cloud functions, web
Specify the query criteria and return a new collection reference with the new query criteria
The query criteria
const _ = db.command
const result = await db.collection('todos').where({
price: _.lt(100)
}).get()
Support: small programs, cloud functions, web
Specifies the maximum number of query result sets
Limit defaults and maximums 20 on small terminals and 1000 on cloud functions
db.collection('todos').limit(10)
.get()
.then(console.log)
.catch(console.error)
Support: small programs, cloud functions, web
Specify the query sort criteria
The method accepts a required string argument fieldName to define the fields that need to be sorted, and a string parameter order defines the sort order. Order can only take asc or desc.
If you need to sort nested fields, you need to connect nested fields with a "point notation", such as style.color, to represent the nested field color in the field style.
It also supports sorting by multiple fields, just call orderBy multiple times, and sort multiple fields in order of orderBy calls
Prioritize to-dos by schedule
db.collection('todos').orderBy('progress', 'asc')
.get()
.then(console.log)
.catch(console.error)
Take the to-dos first in progress descending order (the bigger the progress, the higher the front), and then in the description ascending order (the higher the alphabetical order, the higher the forward):
db.collection('todos')
.orderBy('progress', 'desc')
.orderBy('description', 'asc')
.get()
.then(console.log)
.catch(console.error)
Support: small programs, cloud functions, web
When a specified query returns results, it starts with the results of the specified sequence and is often used for plying
db.collection('todos').skip(10)
.get()
.then(console.log)
.catch(console.error)
Support: small programs, cloud functions, web
Specifies the fields that need to be returned for the record in the return result
The method accepts a required object to specify the field to be returned, the individual keys of the object represent the fields to return or not to return, and value is passed in true|false (or 1|-1) to indicate whether to return or not to return.
Only the description, done, and progress fields are returned:
db.collection('todos').field({
description: true,
done: true,
progress: true,
})
.get()
.then(console.log)
.catch(console.error)