johnlemon
johnlemon

Reputation: 21469

Query mongodb using internal field

I have a collection: people. I wish to query documents where people.lastname = people.firstname

Is this possible ?

Upvotes: 0

Views: 105

Answers (2)

JohnnyHK
JohnnyHK

Reputation: 311935

As Sergio correctly points out, $where has poor performance, but if that's still acceptable to you, this is how you'd do it:

db.people.find( { $where: "this.lastname == this.firstname" } );

Upvotes: 1

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230366

No, this is not possible at the moment (in efficient manner). It might be possible using $where but it has terrible performance and I wouldn't advise using it in real applications.

Upvotes: 0

Related Questions