I am using JOIN statement on IMongoQueryable to join two collections data but getting error if I use join statement. I am using mongodb driver 2.25.0.
Both the collection having same Id , need to combine some fields
var mainCollection = _mainCollection.AsQueryable();
var otherCollection = _otherCollection.AsQueryable();
var sharedQuery = mainCollection
.Join(mainCollection,
main => main.Id,
other => other.Id,
(main, other) => new Entity
{
Id = main.Id,
Model = main.Model,
Body = main.Body,
Status = main.Status,
Version = main.Version,
WorkFlowInfo = other.Body
});
Body is a bsonDocument and group is a field inside this. When I was using 2.18 version of mongodb driver it was working fine. but After upgrade I started getting this error. Need your help here
Welcome to the MongoDB Community Forums. I tried your query with the latest driver and it produced reasonable MQL. I had to make some assumptions about your POCOs and updated your Join to be between main and other rather than main and main. Here is the repro that I ran:
using System;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
var client = new MongoClient();
var db = client.GetDatabase("test");
var main = db.GetCollection<Entity>("main");
var other = db.GetCollection<Entity>("other");
var mainCollection = main.AsQueryable();
var otherCollection = other.AsQueryable();
var sharedQuery = mainCollection
.Join(otherCollection,
main => main.Id,
other => other.Id,
(main, other) => new Entity
{
Id = main.Id,
Model = main.Model,
Body = main.Body,
Status = main.Status,
Version = main.Version,
WorkFlowInfo = other.Body
});
Console.WriteLine(sharedQuery);
public class Entity
{
public ObjectId Id { get; set; }
public string Model { get; set; }
public string Body { get; set; }
public string Status { get; set; }
public string Version { get; set; }
public string WorkFlowInfo { get; set; }
}
.Join(otherCollection,
main => main.Id,
other => other.Id,
(main, other) => new Entity
{
Id = main.Id,
Model = main.Model,
Body = main.Body,
Status = main.Status,
Version = main.Version,
WorkFlowInfo = other.Body
});
New & Unread Topics
Topic list, column headers with buttons are sortable.