0

Is possible that use mongoose $lookup for using across multiple databases? Do you have any idea about this matter?

I have a user DB that contains users info in users collection. and another DB for user's comments.

J.F.
  • 13,927
  • 9
  • 27
  • 65
mehdi parastar
  • 737
  • 4
  • 13
  • 29

1 Answers1

0

As mongoDB docs says about $lookup:

Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing.

So no, answering your question: it's not possible.

But, as an addition, using Mongo exists db.getSiblingDB() option.

Docs here where says:

Used to return another database without modifying the db variable in the shell environment.

And you can check here that in Mongoose the method is called useDb().

Docs here where says:

Switches to a different database using the same connection pool.

So, this is not a $lookup but is an approach to have another Data Base data.

This answer uses useDb and populate, maybe it helps you.

Also for your purpose check this question too.

J.F.
  • 13,927
  • 9
  • 27
  • 65