Tuesday, 14 March 2017

Return a json from inside a schema in MongoDB

I have the following document:

{
  "id": "someString",
  "servers": [
    {
      "name": "ServerName",
      "bases": [
        {
          "name": "Base 1",
          "status": true
        },
        {
          "name": "Base 2",
          "status": false
        }
      ]
    }
  ]
}

I want to create an API route to get a json that contains only the names of the bases that status are true.

My current dependencies of my project are:

"dependencies": {
    "basic-auth": "^1.1.0",
    "body-parser": "~1.0.1",
    "express": "~4.0.0",
    "mongoose": "~4.6.8",
    "mongoose-unique-validator": "^1.0.4",
    "morgan": "~1.0.0"
  }

Any help is appreciated! Thanks!



via Vinícius Rufine

No comments:

Post a Comment