2014년 12월 10일 수요일

how to search two collections based on some condition

how to search two collections based on some condition
Exampe :
collectionA
{ code:"test",name:"sample" }
collectionb
{ code:"test2",name:"sample2" }
collectionc
{ code:"test",name:"sample2" }
check the code:"test" in all collections.



MongoDB only ever searches one collection per query. Searching three collections requires three queries to the database.

    > db.collectionA.find({ "code" : "test" })
    > db.collectionB.find({ "code" : "test" })
    > db.collectionC.find({ "code" : "test" })



You can use Map reduce function for this..



Actually no, you can't.  MapReduce, like all other operations in MongoDB only runs on a single collection per invocation.

Will is correct - it's just three queries, one against each collection.


댓글 없음:

댓글 쓰기