mongod的实际应用

2021-09-25  本文已影响0人  Biao_349d

api 链接 https://www.docs4dev.com/docs/zh/mongodb/v3.6/reference/reference-method-db.collection.aggregate.html

查询条件链接 https://www.docs4dev.com/docs/zh/mongodb/v3.6/reference/reference-operator-query.html

// 查询指定字段所形成的数组;

{ "_id": 1, "dept": "A", "item": { "sku": "111", "color": "red" }, "sizes": [ "S", "M" ] }
{ "_id": 2, "dept": "A", "item": { "sku": "111", "color": "blue" }, "sizes": [ "M", "L" ] }
{ "_id": 3, "dept": "B", "item": { "sku": "222", "color": "blue" }, "sizes": "S" }
{ "_id": 4, "dept": "A", "item": { "sku": "333", "color": "black" }, "sizes": [ "S" ] }


db.inventory.distinct( "dept" )

[ "A", "B" ]

https://www.docs4dev.com/docs/zh/mongodb/v3.6/reference/reference-command-distinct.html

update 更新或插入字段

await DB.Stocktradingday.update(
        {
          id: 1
        },
        {
          $set: {
            datelist: tradingDayList
          }
        },
        {
          upsert: true
        }
      )

查询指定条件并且返回某个字段值的列表

let hardenSymbolList = await stockDailyHisDb.User.distinct('symbol', {
      date: {
        $eq: startTime
        // $lte: startTime
      },
      // 涨幅小于9.5
      percent: {
        $gte: 9.5
      }
    });

匹配符号

https://www.docs4dev.com/docs/zh/mongodb/v3.6/reference/reference-operator-aggregation-avg.html

上一篇下一篇

猜你喜欢

热点阅读