Objective
It is well known that the current use of Node.js + MongoDB has become a technology stack for many companies. Thinkjs actually provides support for MONGO, although the official documentation is small, but the ORM API is guaranteed to be consistent, so use it to see the basic >model API
The basic model files are placed under Common/model
Get list
GetList (q, page) {
Returnthis.select ();
}
|
Paging Plus Conditional Search
Search (q, page) {
if (q) {
Q =newregexp (q, ' I ');
}
Returnthis.where ({' name ': {$regex: Q}}). page (page). Countselect ();
}
|
Get details
Getdetail (ID) {
Returnthis.where ({' _id ': id}). Select ();
}
|
Creating data
Addtag (TAG) {
Returnthis.add (tag);
}
|
Update data
Updatetag (Id,data) {
Returnthis.where ({' _id ': ID}). Update (data);
}
|
Delete data
Removeone (ID) {
Returnthis.where ({' _id ': id}). Delete ();
}
|
So what you need is just the way to call the appropriate model.
A simple interface is as follows:
Async CreateAction () {
Let name =this.post (' name ');
Let contents =this.post (' contents ');
Get model Instance
Let M =this.model (' tag ');
Let res = await M.addtag ({
' Name ': Name,
' Contents ': Contents,
' Count ': 0,
});
if (res) {
This.success (");
}else{
This.apierrorhandle (4000);
}
}
....
|