2

I have two collections in mongodb.I am retreiving data from two collections independently working gud.But when I am implementing paging using skip and take methods I am getting data from both the collections like this

paging = new Pagination() { CurrentPage = pageNumber, ItemsPerPage = 16 };
var results = dataTable.FindAs<TradeInfo(queryAll).Skip(paging.Skip).Take(paging.Take).ToList<TradeInfo>();
paging.TotalCount = Convert.ToInt32(dataTable.Find(query).Count());
var results2 = new List<TradeInfo>();
if (dataTable2 != null)
{
    results2 = dataTable2.FindAs<TradeInfo(queryAll).Skip(paging.Skip).Take(paging.Take).ToList<TradeInfo>();
    int count = Convert.ToInt32(dataTable2.Find(query).Count());
    paging.TotalCount = paging.TotalCount + count;
    results.AddRange(results2);
 }

I am giving results as Itemssource to Datagrid and I am getting total 32 items per page. How can I do that is there any joins concept in Mongodb.Two collections columns are same. How can I do it? Please help me in doing that....

Thanks, jan

i3arnon
  • 113,022
  • 33
  • 324
  • 344
jan
  • 21
  • 2
  • Does the answers to this question: http://stackoverflow.com/questions/2350495/how-do-i-perform-the-sql-join-equivalent-in-mongodb help? – Christian Horsdal Jan 18 '12 at 07:54
  • No in two collections i have same column names but not the same data its some thing like concatenating the two strings as concatenating two collections – jan Jan 18 '12 at 09:14

1 Answers1

0

I believe what you are looking for here is more of a Union than a Join.

Unfortunately there is no such concept in MongoDB. If your paging is dependent on a query, which in this case it seems it might be, your only real option is to create and maintain a single merged collection which gets updated every time a document is added or saved to either of these two collections. Then you can skip and take on the single collection after applying the query to it.

Zaid Masud
  • 13,225
  • 9
  • 67
  • 88