当前位置:网站首页>Schema和Model
Schema和Model
2022-07-05 20:11:00 【为什么不好好卖蛋饼】
16 Schema和Model
Schema
Model
Document
顺序从上往下
var mongoose=require("mongoose");
mongoose.connect('mongodb://数据库ip地址:端口号/数据库名',{
userMongoClient:true});
mongoose.connection.once("open",function(){
console.log("数据库连接成功");
});
//创建模式对象
var Schema=mongoose.Schema;
var stuSchema=new Schema({
title:String,
age:Number,
gender:{
type:String,
default:"female"
},
address:String
});
//model代表集合,通过model才能对数据库操作
var StuModel=mongoose.model('Student',stuSchema);
//向数据库插入一个文档
StuModel.create({
name:"孙悟空",
age"18,
gender:"male",
address:"花果山"
},function(err){
if(!err){
console.log("插入成功");
}
});
创建模型(集合名,约束对象)
模型操作数据库
边栏推荐
- JVMRandom不可设置种子|问题追溯|源码追溯
- ICTCLAS word Lucene 4.9 binding
- 2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
- Oracle-表空间管理
- [C language] three implementations of quick sorting and optimization details
- 【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
- Debezium series: idea integrates lexical and grammatical analysis ANTLR, and check the DDL, DML and other statements supported by debezium
- . Net distributed transaction and landing solution
- [C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp
- BZOJ 3747 POI2015 Kinoman 段树
猜你喜欢
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
Securerandom things | true and false random numbers
Jvmrandom cannot set seeds | problem tracing | source code tracing
leetcode刷题:二叉树11(平衡二叉树)
leetcode刷题:二叉树13(相同的树)
leetcode刷题:二叉树15(找树左下角的值)
JVMRandom不可设置种子|问题追溯|源码追溯
Go language | 02 for loop and the use of common functions
618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
随机推荐
【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
银河证券在网上开户安全吗?
Codeforces Round #804 (Div. 2) - A, B, C
点云文件的.dat文件读取保存
解决php无法将string转换为json的办法
selenium 元素信息
建立自己的网站(16)
Float. The specific meaning of the return value of floattorawintbits is to convert float into byte array
Cocos2d-x项目总结中的一些遇到的问题
[C language] three implementations of quick sorting and optimization details
SecureRandom那些事|真伪随机数
Flume series: interceptor filtering data
1:引文;
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
中金财富在网上开户安全吗?
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
信息学奥赛一本通 1337:【例3-2】单词查找树 | 洛谷 P5755 [NOI2000] 单词查找树
2022年7月4日-2022年7月10日(ue4视频教程mysql)
c——顺序结构
Leetcode(695)——岛屿的最大面积