top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Is there a way to compare two fields from different MongoDB Collections?

+2 votes
472 views

Is there a way to compare two fields from different MongoDB Collections?

I have a 2 collections:
collection_1: { "english" : { "orth" : "africa", "pron" : "frik" }, "francais" : { "orth" : "afrique" } }
collection_2: { "form" : { "orth" : "afrique", "pron" : "afik" } "sense" : { "cit" : { "quote" : "africa" } }}

I would like to find all where "collection_1.english.orth" == "collection_2.form.orth" and copy/add "form.pron" from collection_2 into collection_1 under "francais.pron".

posted Jan 26, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

As we cannot perform join operations in mongodb as mysql but we can try by using php cursors
use
foreach($cursor_collection_1 as $value_1)
{
foreach($cursor_collection_2 as $value_2)
{
//do operations //

}
}
Recently I used this method in one of my mongodb operations.It works.

answer Jan 26, 2016 by Shivam Kumar Pandey
Similar Questions
+2 votes

Is there a way to configure/increase the memory limit(100MB) on the pipeline? What if I have a lot of RAM that can be used by MongoDB?

+1 vote

I have a project, which has 1000 images. From each image, I get 1 million documents that I currently store in a mongoDB collection.

I have 2 alternatives,
1. Create a separate collection for each image, over multiple projects, say 10 projects, and each image(collection) would have 1 million documents that will be indexed. OR
2. Have a single collection and have 1000x1,000,000 documents in one collection, which again will be indexed.

My research and reading suggests that it is not a very good idea to create 1000 collections (for each image) and create an index for each one of 1000, and go with adding a billion documents to a single collection, to which mongoDB caters with no major issue.
My main aim is to enhance performance for reading. There would be no updates and deletes. Only reads and writes. I can afford writes to be slow, but not reads. So am I right in choosing the 2nd alternative?

Any guidance is highly appreciated.

...