1

i am newbie in Mongodb and i want to create query with sibling keys but i'm unable. Let's clear with example:-

Here is my mongodb document:-

{
    userId:1,
    name:'abc',
    game:{
        gener:'puzzle',
        gId:4
        gRid:12,
        mTepCount:890,
        pT:'high',
        related:[{
            gRid:14,
            name:'xyz',
            count:230
        },{
            gRid:12,
            name:'yzdd',
            count:300
        }]

    }
}

I have written query like this, but not working,

db.test.aggregate([{
    $match:{
        'game.gRid':'game.related.gRid'
    }
}])

In Sql, the query will be like ,

1) SELECT a.name,b.count from a INNER JOIN b ON a.gRid=b.gRid  WHERE pT='high'
tts
  • 53
  • 1
  • 6
  • Possible duplicate of [Compare between 2 fields of a document in MongoDB](https://stackoverflow.com/questions/45853476/compare-between-2-fields-of-a-document-in-mongodb) – glytching Aug 28 '17 at 15:44

1 Answers1

1

Here is a good answer from @Ian about how to compare fields together.

  db.test.find( { $where : "this.gRid > this.related.gRid" } );
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69