how can i use joins in mongodb ?

1,342 views
Skip to first unread message

rahil shareef

unread,
Jul 23, 2016, 5:11:19 PM7/23/16
to mongodb-user
hi,
i am using latest mongodb 3.2.8 with c#. 

i want to use joins .

kindly help me.

thank you

Senthil

unread,
Jul 24, 2016, 4:21:02 PM7/24/16
to mongodb-user
No joins in Mongo db.  Mongodb provided flexibility to create relational in the single document to avoid joins unlike to create multiple tables with cross referenced in  traditional RDBMS

William Hagan

unread,
Jul 25, 2016, 3:29:37 PM7/25/16
to mongodb-user
Do check out the $lookup stage of the aggregation operator to see if it addresses your need.

Cheers

Wan Bachtiar

unread,
Jul 31, 2016, 11:18:46 PM7/31/16
to mongodb-user

i am using latest mongodb 3.2.8 with c#. i want to use joins .

Hi rahil,

As mentioned by William, you can try the aggregation operator $lookup. The $lookup operator is available starting from MongoDB v3.2.

An example of C# $lookup snippet using MongoDB .Net driver, currently at version 2.2:

var query = from p in collection.AsQueryable()
            join o in otherCollection on p.Name equals o.Key into joined
            select new { p.Name, AgeSum: joined.Sum(x => x.Age) };

See mongo-csharp-driver $lookup LINQ for more information.

If you are requiring joins for a frequently used query in your application or use case, I would recommend to re-consider your data models/schema.
See also the following data modelling resources:

You may also be interested to know that the next session for free online course M101N: MongoDB for .Net Developers is starting tomorrow, 2nd of August. This course will go over schema design, querying, insertion of data, indexing and working with the C# driver.

Best regards,

Wan

Reply all
Reply to author
Forward
0 new messages