【发布时间】:2019-06-20 20:46:17
【问题描述】:
我正在开发一个 MEAN 应用程序,并尝试使用 FAWN 对 MongoDB 实现类似行为的事务。我正在使用猫鼬库。当我使用小鹿时,数据有点跳过模式条件,例如 min: 1 for sellPrice。但是,我也在运行中使用 { useMongoose: true }。
var mongoose = require('mongoose');
var Fawn = require('fawn');
Fawn.init(mongoose);
//Function code is as follow
var task = Fawn.Task();
let item = await Item.findById(req.params.id);
task.update('items', {_id: item._id}, {type: req.body.type, name: req.body.name, sku: req.body.sku, openingStock: req.body.openingStock, availableStock: req.body.availableStock, purchasePrice: req.body.purchasePrice, sellingPrice: req.body.sellingPrice, profitMargin: req.body.profitMargin, reorderLevel: req.body.reorderLevel, preferredVendor: req.body.preferredVendor});
task.update('items', {_id: item._id}, {sellingPrice: -50});//This line should fail because min value for sellingPrice is 1
task.run({ useMongoose: true })
.then(function(){res.json(item);})
.catch(function(error){res.json({error: {"message": error}});});
【问题讨论】:
标签: node.js mongodb mongoose mean-stack mongoose-schema