美文网首页
MongoDB数据库查询更新语句

MongoDB数据库查询更新语句

作者: danihay | 来源:发表于2017-10-24 12:44 被阅读21次
  1. 在表格中查找status不为 '待采购'的数据
db.getCollection('goodsApply').find({status:{$ne: '待采购'} })
  1. 在表格中查找sendWay不为 '快递'的数据以createdAt的顺序排列
db.getCollection('goodsApply').find({sendWay: {$ne: '快递'} }).sort({createdAt:-1})
  1. 在表格中查找sendWay不为 '快递'的数据以createdAt的顺序排列,最多30条
db.getCollection('goodsApply').find({sendWay: {$ne: '快递'} }).sort({createdAt:-1}).limit(30)
  1. 更新数据表中的数组里面的字段
Collections.GoodsApply.update(
          {_id: goodApplyId, 'goods._id': good._id },
          { $set: { 'goods.$.name': _product.name, 'goods.$.id': _product.id}}
); 
开始数据形式如下
{
_id: '123',
status: 1,
goods: [{
      _id: 'abs',
      age: 23,
},{
      _id: 'ays',
      age: 23,
      amount: 2,
},{
      _id: 'ayt',
      amount: 3,
}]
}

相关文章

网友评论

      本文标题:MongoDB数据库查询更新语句

      本文链接:https://www.haomeiwen.com/subject/cxvtpxtx.html