node --更新数据库(mongoose提供的update)

1、视图

2、表结构

{
    "_id" : ObjectId("5b46b725473038c4d45e1ad7"),
    "userId" : 1110,
    "userName" : "Lily",
    "userPwd" : "333",
    "salePrice" : 249.0,
    "goodsSale" : [ 
        {
            "goodsId" : 1,
            "goodsName" : "电视",
            "goodsPrice" : 18,
            "isselected" : true,
            "imgsrc" : "1.jpg",
            "shopcarNum" : 2
        }, 
        {
            "goodsId" : 2,
            "goodsName" : "电脑",
            "goodsPrice" : 19,
            "isselected" : false,
            "imgsrc" : "2.jpg",
            "shopcarNum" : 3
        }, 
        {
            "goodsId" : 3,
            "goodsName" : "笔记本",
            "goodsPrice" : 10,
            "isselected" : true,
            "imgsrc" : "2.jpg",
            "shopcarNum" : 1
        }
    ]
}

3、更新表结构(更新表结构的子文档)

	   var userId=1110,
	   goodsId=1,
	   shopcarNum=3
	   Users.update({"userId":userId,goodsSale.goodsId:goodsId},{
	   	   "goodsSale.$.shopcarNum":shopcarNum,
	   	   
	   })

你可能感兴趣的:(node --更新数据库(mongoose提供的update))