随笔分类 -  mongodb笔记

摘要:let photoId = mongoose.Types.ObjectId(`${virtual.productId[0]}`) await model.photo.findByIdAndUpdate(photoId, { $set: { photto: photo } }, { upsert: t 阅读全文
posted @ 2018-05-24 18:45 江山一族 阅读(586) 评论(0) 推荐(0)
摘要:1."$gt" 、"$gte"、 "$lt"、 "$lte"、"null查询"、"$all"、"$size"、"$in"、"$nin"、"$and"、"$nor"、"$not"、"$or"、"$exists"、"$mod"、"$regex"、"$where"、 阅读全文
posted @ 2018-05-21 10:59 江山一族 阅读(818) 评论(0) 推荐(0)
摘要:一、$group 进行分组 1、每个职位的雇员人数: db.getCollection('emp').aggregate( [ {'$group':{ ‘_id’:'$job', job_count:{'$sum':1} } } ] ) 2、每个职位的总工资 db.getCollection('em 阅读全文
posted @ 2018-05-17 23:06 江山一族 阅读(2563) 评论(0) 推荐(0)
摘要:1.$inc: 对数字字段内容进行修改 db.getCollection('student').update( {'age':19}, {$inc:{'score':-20}} ) 2.$set :对字段内容进行修改 3.$unset :对字段内容进行删除 db.getCollection('stu 阅读全文
posted @ 2018-05-16 22:30 江山一族 阅读(159) 评论(0) 推荐(0)
摘要:db.getCollections('students').update({},{$set:{}},{upsert:false,multi:false}) 更新单行,upsert为true时,更新不存在的数据,即为添加数据 db.getCollections('students').update({ 阅读全文
posted @ 2018-05-15 23:36 江山一族 阅读(161) 评论(0) 推荐(0)
摘要:1、查询课程中包含math,chinese的课程 db.getCollection('student').find( { course:{$all:['math','chinese']} } ).pretty() 2.查询第二门课程是数学 db.getCollection('student').fi 阅读全文
posted @ 2018-05-14 23:34 江山一族 阅读(229) 评论(0) 推荐(0)
摘要:var user = db.getCollection('user') //user.find({},{_id:0}).pretty().count() user.find({age:{$gte:25,$lt:70}},{_id:-1}) .sort({age:-1}) .skip(2).limit 阅读全文
posted @ 2018-04-08 17:05 江山一族 阅读(7361) 评论(0) 推荐(0)