sql >> Database teknologi >  >> NoSQL >> MongoDB

Hvis andet hvis kond i mongodb aggregering

Du kan bruge $switch aggregering i stedet.

Schedul.aggregate([
  { "$match": { "flag": 1 }},
  { "$project": {
    "name": "$name",
    "day_of_week": {
      "$switch": {
        "branches": [
          { "case": { "$eq": ["$day_of_week", 0] }, "then": "Sunday" },
          { "case": { "$eq": ["$day_of_week", 1] }, "then": "Monday" },
          { "case": { "$eq": ["$day_of_week", 2] }, "then": "Tuesday" },
          { "case": { "$eq": ["$day_of_week", 3] }, "then": "Wednesday" },
          { "case": { "$eq": ["$day_of_week", 4] }, "then": "Thrusday" },
          { "case": { "$eq": ["$day_of_week", 5] }, "then": "Friday" }
        ],
        "default": "Saturday"
      }
    }
  }}
])



  1. Hvorfor giver PyMongo 3 ServerSelectionTimeoutError?

  2. MongoDB bedste praksis til at tælle relaterede dokumenter

  3. Upsert Multiple Records med MongoDb

  4. Mongodb C# masseopdatering/erstat på undersamling