2

I have a collection in MongoDb called items items contain two types of item 1) pizza 2) drinks

how I query just the pizza if my mongoose schema was like this:

let items = new Schema({
    pizza: {
        name: String,
        price: [Number],
        subType: [String]
    },

    drinks : {
        name: String,
        price: Number,

    }
})
SMH
  • 889
  • 3
  • 11
  • 30
  • Possible duplicate of [Check that Field Exists with MongoDB](http://stackoverflow.com/questions/19868016/check-that-field-exists-with-mongodb) – styvane Dec 07 '16 at 17:58

1 Answers1

2

You can use the second argument of find operation to select only a subset of fields you want in the output. You can read about find at this link

The query as given below should be what you should be interested in.

db.coll.find({}, {pizza: 1})
hyades
  • 3,110
  • 1
  • 17
  • 36