0

How to write following SQL query in mongodb ?

Select * from table t where t.col1=t.col2

Sagar
  • 5,315
  • 6
  • 37
  • 66

1 Answers1

1

You should use $redact aggregation operator which:

Restricts the contents of the documents based on information stored in the documents themselves.

For instance:

db.col.save({a: 1, b: 1});
db.col.save({a: 2, b: 1});

db.col.aggregate([
    { $redact: {
        $cond: {
           if: { $eq: [ "$a", "$b" ] },
           then: "$$KEEP",
           else: "$$PRUNE"
         }
       }
     }
])
mickl
  • 48,568
  • 9
  • 60
  • 89