mongodb advantages and disadvantages

mongodb switch expression

Syntax:

    {$project: {
        columnName: {
            $switch: {
                branches: [
                    {
                        case: <your-expression>,
                        then: <your-expression>
                    }                   
                ],
                default: <optional, your-expression>
            }
        }
    }}

Example

db.customers.aggregate([{
  $project: {
    customer: {
      $switch: {
        branches: [
          {
            case: {$eq: ["$Id", 0]},
            then: "Zero!"
          }
        ],
        default: "do something else!"
      }
    }
  }
}])

For more detail, go to links


ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.