Jürgen Paul
Jürgen Paul

Reputation: 14997

Search documents which has specific column in mongo

db.posts.insert({
    title: "Hello World",
    "2d": [1,2],
    "3d": [3,4,5],
    "4d": [6,7,8,9],
    "6d: [1,2,3,4,5,6]
});

Each document can have only the 2d column, or just the 3d column, or just the both, or just 4d and 2d, etc. How do I find documents which has that specific column?

SELECT * FROM posts where posts.hascolumn=2d

^Just for demonstration.

Upvotes: 0

Views: 176

Answers (1)

Alexey Ogarkov
Alexey Ogarkov

Reputation: 2916

You can use db.posts.find({"2d" : {$exists:true})

Upvotes: 1

Related Questions