MongoDB跨数据库查询 [英] MongoDB cross database query

查看:1140
本文介绍了MongoDB跨数据库查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我已经在某处看到了此解决方案,但现在似乎找不到.我试图在连接到另一个数据库时查询一个MongoDB数据库.在运行查询之前,无需显式连接到其他数据库,这应该是可能的.有谁知道正确的语法来做到这一点?

I know I've seen this solution somewhere, but I can't seem to find it now. I'm trying to query one MongoDB database while connected to another. This should be possible without explicitly connecting to the other database before running the query. Does anyone know the correct syntax to do this?

推荐答案

要针对同一MongoDB服务器上的另一个数据库运行命令,请在mongo shell中使用:

To run a command against another database on the same MongoDB server, in the mongo shell you can use:

db.getSiblingDB('dbname').collection.command()

例如:

db.getSiblingDB('test').foo.find()

这篇关于MongoDB跨数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆