
数据库
seaalan
这个作者很懒,什么都没留下…
展开
-
Mongodb - 备份恢复
备份 $ ./mongodump -h localhost:27017 -d sp-development -o /d/works/DB/ -u user -p 123gogogo恢复 $ ./mongorestore -h localhost:27017 -d sp-development-conmmon --dir /d/works/DB/sp-development-common/...原创 2018-10-12 16:05:17 · 108 阅读 · 0 评论 -
Mongoose - Schema
Mongoose 里,一切都始于Schema。Schema定义:允许使用的 SchemaTypes 有String, Number, Date, Buffer, Boolean, Mixed, ObjectId, Array, Decimal128, Mapvar Schema = mongoose.Schema;var kittySchema = new Schema({ n...原创 2019-04-23 12:16:50 · 513 阅读 · 0 评论 -
Mongoose - 连接
安装mongoosenpm install mongoose连接本地数据库mongoose-testvar mongoose = require('mongoose');mongoose.connect('mongodb://localhost:27017/mongoose-test');var db = mongoose.connection;db.on('error', con...原创 2019-04-23 10:25:34 · 687 阅读 · 0 评论 -
Mongoose - distinct方法
示例数据:{ "_id" : ObjectId("5c9d8cc3161d6c257c021340"), "email" : "123@123com"}{ "_id" : ObjectId("5ca2bc4a54bc0f2fa07b1541") "email" : "234@234.com"}{ "_id" : ObjectId("5ca2cb7a...原创 2019-04-12 18:40:16 · 2880 阅读 · 0 评论 -
Mongoose - count和countDocuments方法
This method is deprecated. If you want to count the number of documents in a collection, e.g. count({}), use the estimatedDocumentCount() function instead. Otherwise, use the countDocuments() function...原创 2019-04-11 18:26:44 · 15955 阅读 · 4 评论 -
Mongoose - 嵌套查询
示例数据:{ "_id" : ObjectId("5ca560896208983d3c55b87e"), "createdBy" : { "kind" : "admin", "item" : ObjectId("5c9d84c98a007636043f1fe6") }}完全匹配嵌套数据进行查询:db.getCollection('x...原创 2019-04-11 17:45:23 · 1659 阅读 · 0 评论 -
Mongoose - 排序sort
目的:按照字母升序排序,并且不区分大小写。示例数据如下。{"lastName" : "guo"}{"lastName" : "LLL"}{"lastName" : "zzz"}{"lastName" : "ccc"}db.getCollection(‘users’).find({}).sort({‘lastName’:1}) 执行排序后的结果如下:{"lastName" : "LL...原创 2019-04-02 12:30:56 · 7654 阅读 · 0 评论 -
Mongoose - 方法定义
定义Schemalet mongoose = require('mongoose'), Schema = mongoose.Schema;let UserSchema = new Schema({ fullName: {// 姓名 PHARMACIST_FULLNAME type: String }, sex: {// 性别 PHARMACIST...原创 2019-03-04 11:24:50 · 422 阅读 · 0 评论 -
Mongoose - Schema示例
let RegistrationCodeSchema = new Schema({ phone: {// 电话 type: String, // 数据类型 default: 0, // 默认值 lowercase: true, // 英文全小写 unique: true, // 唯一性 trim: true, ...原创 2019-01-10 09:56:40 · 428 阅读 · 0 评论 -
Mongoose - 一次更新多条数据updateMany
Order.updateMany({ created: {$gte: new Date(new Date().getTime() - 1 * 60 * 60 * 1000)}, $or: [{practiceUnit: {$exists: false}}, {practiceUnit: ''}], status: 'waiti...原创 2018-12-24 15:01:00 · 32363 阅读 · 0 评论 -
Mongoose -查询条件
$lt 小于$lte 小于等于$gt 大于$gte 大于等于 {created: {$gte: new Date(new Date().getTime() - 1 * 60 * 60 * 1000)}}$eq 等于$ne 不等于 {age: { $ne:24}}$in 一个键对应多个值 {age: {$in:[20,30]}}$nin 一个键不对应指定值$or 多个条件匹配, 可以...原创 2018-12-24 14:59:40 · 4531 阅读 · 0 评论 -
Mongoose - 一次录入多条数据insertMany
使用 insertMany// 出入资料{ "list":[ { "areaOfPharmacistBackup":"湖北省武汉市黄陂区", "nameOfPharmacistBackup":"鲁**", "typeOfPharmacistBackup"原创 2018-12-21 12:40:41 · 12416 阅读 · 0 评论 -
Mongoose - 多层populate
DrugOrder.findById(drugOrderId, '-updated -__v') .populate({ path: 'orderId', select: 'prescription checkResult.checkResultFlag checkResult.checkResultDetail',...原创 2018-12-12 14:26:58 · 882 阅读 · 0 评论 -
Mongoose - mapReduce
使用mongoose中的mapReduce方法统计结果。示例,以审方订单中药师为key进行统计,统计出每个药师的审方订单数量。var o = {}; // `map()` and `reduce()` are run on the MongoDB server, not Node.js, // these functions are converted to strings ...原创 2018-11-19 16:34:42 · 1012 阅读 · 0 评论 -
Mongoose - markModified
mongoose中使用save方法修改嵌套数据时,添加order.markModified(‘checkResult’);这句,以完成修改操作,否则无法修改嵌套数据。order = _.merge(order, req.body);order.markModified('checkResult');order.save() .then(() => { ret...原创 2018-11-19 12:38:49 · 1288 阅读 · 0 评论 -
Mongoose - Saving a model fails with mongo error: MongoError: Unknown modifier: $pushAll
Order.findById(orderId) .populate( [{ path: 'prescription' }] ) // .lean() .then(order => { theOrder = order; ...原创 2018-11-07 18:09:45 · 884 阅读 · 0 评论 -
Mongoose - lean
lean属性的作用:转换mongoose查询结果类型,从MongooseDocuments转换为JS Object,从而便于我们修改查询结果。mongoose查询:Model.findOne({})Model.save()以上2中查询返回的数据实际上是MongooseDocuments对象(mongoose自己封装的一个对象),并且这个对象会对数据进行实时查询以保证其符合预定义的mod...原创 2018-10-15 13:11:10 · 7158 阅读 · 0 评论 -
Mongoose - 一次删除多条数据deleteMany
ItemCheckOfArchive.deleteMany({_id: {$in: itemCheckLists}})原创 2019-05-05 18:31:19 · 13182 阅读 · 0 评论