当前位置:网站首页>Model method
Model method
2022-07-05 20:17:00 【Why not sell egg cakes well】
17 Model Method
Model It's a constructor
Model.create(doc(s),[callback])
Create a document and add it to the database
Parameters doc(s) Can be a document object , It can also be an array .
callback Optional Callback function that is called when the operation is completed. .
// Inquire about
Model.find()
condition- Query criteria
projection Projection Fields to get
Two ways
{
name:1,_id:0}
"name age -_id"
option-- Query options skip limit
callback Callback function The callback function must pass , If not , Will not query .
// Always return an array
StuModel.find({
name:" Tang's monk "},function(err,docs){
if(!err){
console.log(docs);
}
}
);
StuModel.find({
},{
name:1,_id:0},function(err,docs){
if(!err){
//doc yes Document Document object , yes model Example .
console.log(docs);
}
}
);
StuModel.find({
},"name age -_id",function(err,docs){
if(!err){
console.log(doc instanceof StuModel);
}
}
);
modify
conditions Query criteria
doc Modified objects
options Configuration parameters
callback Callback function
StuModel.updateOne({
name:" Tang's monk "},{
$set:{
age:20}},function(err){
if(!err){
console.log(" Modification successful ");
}
});
Delete
StuModel.remove({
name:" Bones jing "},function(err){
if(!err){
console.log(" Delete successful ");
}
});
Statistical quantity Count
Model.count(conditions,[callback])
StuModel.count({},function(err,count){
if(!err){
console.log(count);
}
});
边栏推荐
- mongodb基操的练习
- 【c语言】快速排序的三种实现以及优化细节
- Mysql频繁操作出现锁表问题
- 【数字IC验证快速入门】3、数字IC设计全流程介绍
- 【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
- Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
- Zero cloud new UI design
- Leetcode brush question: binary tree 14 (sum of left leaves)
- 95后阿里P7晒出工资单:狠补了这个,真香...
- BZOJ 3747 POI2015 Kinoman 段树
猜你喜欢
A way to calculate LNX
走入并行的世界
Unity编辑器扩展 UI控件篇
Build your own website (16)
.Net分布式事務及落地解决方案
SecureRandom那些事|真伪随机数
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
Leetcode brush question: binary tree 14 (sum of left leaves)
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
Leetcode skimming: binary tree 12 (all paths of binary tree)
随机推荐
Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
图嵌入Graph embedding学习笔记
Oracle tablespace management
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
Reinforcement learning - learning notes 4 | actor critical
信息学奥赛一本通 1338:【例3-3】医院设置 | 洛谷 P1364 医院设置
model方法
Codeforces Round #804 (Div. 2) - A, B, C
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
.Net分布式事務及落地解决方案
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
C langue OJ obtenir PE, ACM démarrer OJ
【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
SecureRandom那些事|真伪随机数
股票开户哪里好?网上客户经理开户安全吗
《乔布斯传》英文原著重点词汇笔记(十二)【 chapter ten & eleven】
2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
Is it safe for Guosen Securities to open an account online?
Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
Go language learning tutorial (16)