How to write following SQL query in mongodb ?
Select * from table t where t.col1=t.col2
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"
}
}
}
])