We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
最近在写一个由node koa2 mongodb创建的一个后台接口服务的这么一个项目, 可能会遇到各式各样的问题, 故而以此来记录.
node koa2 mongodb
在对db做CURD时这里使用mongoose. 集成了一些方法, 调用起来方便快捷. 使用collection时一般会这样调用, model中:
db
CURD
mongoose
collection
model
const mongoose = require('mongoose'); const Schema = mongoose.Schema; const userSchema = ({ name: String, password: String }); module.exports = mongoose.model('User', userSchema);
给User添加一些数据后
User
const mongoose = require('mongoose'); const Schema = mongoose.Schema; const userSchema = ({ name: String, password: String }); const userController = mongoose.model('User', userSchema); // 添加数据 const res = new userController({ name: 'admin', password: '123456'}).save();
执行成功后在数据库中查看
> user 你的数据库名 > show collections users
只能查看到有users这个文档, 而不是想象中的user.
users
user
这里的问题出在创建model时, 在mongoose.model()这里可以传入三个参数
mongoose.model()
到这里也就分析出症结所在, 只需要再加入一个参数即可.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
mongodb折腾记
mongoose创建collection时自动加入s
在对
db
做CURD
时这里使用mongoose
. 集成了一些方法, 调用起来方便快捷.使用
collection
时一般会这样调用,model
中:给
User
添加一些数据后执行成功后在数据库中查看
> user 你的数据库名 > show collections users
只能查看到有
users
这个文档, 而不是想象中的user
.这里的问题出在创建
model
时, 在mongoose.model()
这里可以传入三个参数到这里也就分析出症结所在, 只需要再加入一个参数即可.
The text was updated successfully, but these errors were encountered: