SMH
SMH

Reputation: 1099

How to query all items in MongoDb

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,

    }
})

Upvotes: 2

Views: 75

Answers (1)

hyades
hyades

Reputation: 3170

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})

Upvotes: 2

Related Questions