mongoose crud

简介:
Js代码   收藏代码
  1. exports.insert = function(modelname, data) {  
  2.     var model = require('./models/' + modelname);  
  3.     model.create(data, function(err, doc) {  
  4.         if (err)  
  5.             return next(err);  
  6.     });  
  7. };  
  8.   
  9. //Model.remove = function remove (conditions, callback) {  
  10. exports.remove = function(modelname, conditions, callback) {  
  11.     var model = require('./models/' + modelname);  
  12.     model.remove(conditions, function(err, doc) {  
  13.         if (err)  
  14.             return next(err);  
  15.     });  
  16. };  
  17.   
  18.   
  19. //Model.update = function update (conditions, doc, options, callback) {  
  20. //doc new documents  
  21. //  
  22. //Valid options:  
  23. //safe (boolean) safe mode (defaults to value set in schema (true))   
  24. //upsert (boolean) whether to create the doc if it doesn't match (false)   
  25. //multi (boolean) whether multiple documents should be updated (false)   
  26. //strict (boolean) overrides the strict option for this update   
  27. //overwrite (boolean) disables update-only mode, allowing you to overwrite the doc (false)   
  28.   
  29. exports.update = function(modelname, conditions, doc, options, callback) {  
  30.     var model = require('./models/' + modelname);  
  31.     var options = {};  
  32.     model.update(conditions, doc, options, function(err, doc) {  
  33.         console.log(doc + "," + err);  
  34.     });  
  35. };  
  36.   
  37.   
  38. //  Model.find(match, select, options.options, function (err, vals)  
  39. //Model.find = function find (conditions, fields, options, callback)   
  40. exports.find = function(modelname, data) {  
  41.     var model = require('./models/' + modelname);  
  42.     model.find(data, function(err, doc) {  
  43.         if (err)  
  44.             return next(err);  
  45.     });  
  46. };  
  47.   
  48. /** 
  49.  * @param {Object} conditions 
  50.  * @param {Object} [fields] optional fields to select 
  51.  * @param {Object} [options] optional 
  52.  * @param {Function} [callback] 
  53.  * @return {Query} 
  54.  * @see field selection #query_Query-select 
  55.  * @see promise #promise-js 
  56.  * @api public 
  57.  */  
  58. exports.find = function find (modelname,conditions, fields, options, callback) {  
  59.     var model = require('./models/' + modelname);  
  60.     model.find(conditions, fields, options,function (){  
  61.           
  62.     });  
  63. };  
  64.   
  65. //Model.findById = function findById (id, fields, options, callback) {  
  66. //  return this.findOne({ _id: id }, fields, options, callback);  
  67. //};  
  68. exports.findOne = function(modelname, fields, options, callback){  
  69.     var model = require('./models/' + modelname);  
  70.     model.findOne(fields, function() {  
  71.          
  72.     });  
  73. };  
  74.   
  75.   
  76.   
  77. //Model.findOneAndUpdate = function (conditions, update, options, callback)  
  78. exports.findOneAndUpdate = function(modelname, conditions, update, options, callback){  
  79.     var model = require('./models/' + modelname);  
  80.     model.findOneAndUpdate(conditions, update, options, function() {  
  81. //       this.callback.apply();  
  82.     });  
  83. };  
相关文章
|
5月前
|
前端开发 关系型数据库 数据库
使用 Flask 连接数据库和用户登录功能进行数据库的CRUD
使用 Flask 连接数据库和用户登录功能进行数据库的CRUD
109 0
|
11月前
|
JavaScript 前端开发 Java
LayUI之CRUD(增删改查功能实现)项目案例
LayUI之CRUD(增删改查功能实现)项目案例
76 0
|
11月前
|
存储 JSON 前端开发
LayUI之CRUD(增删改查)
LayUI之CRUD(增删改查)
118 0
|
11月前
|
存储 前端开发 JavaScript
Layui的CRUD(增删改查)
Layui的CRUD(增删改查)
99 0
|
前端开发 JavaScript API
Layui的CRUD(增删改查)
Layui的CRUD(增删改查)
102 0
|
前端开发 数据管理 数据库
Layui之CRUD(增删改查)
Layui之CRUD(增删改查)
41 0
|
12天前
|
数据可视化 API PHP
学生信息管理系统-可视化-科目管理CRUD代码生成器
学生信息管理系统-可视化-科目管理CRUD代码生成器
29 5
|
1月前
|
前端开发 IDE 数据库连接
ThinkPHP6 模型层的模型属性,表映射关系,以及如何在控制层中使用模型层和模型层中的简单CRUD
本文详细介绍了ThinkPHP6中模型层的使用,包括模型属性设置、表映射关系、以及如何在控制层中使用模型层进行CRUD操作。
ThinkPHP6 模型层的模型属性,表映射关系,以及如何在控制层中使用模型层和模型层中的简单CRUD
|
2月前
|
API Python
[gin]基于切片实现crud
[gin]基于切片实现crud
|
2月前
|
前端开发 Java 关系型数据库
通过HTML网页对mysql数据库进行增删改查(CRUD实例)
通过HTML网页对mysql数据库进行增删改查(CRUD实例)
187 0