我学习了如何使用db.siblingsDB和db.sisterDB。但我不能同时使用它们来创建来自不同数据库的视图。
我尝试过的示例查询是:
use "database1"
var users = db.getSiblingDB("database2").getCollection("User").find({})
db.runCommand({
"create" : "VW_User",
"viewOn" : users,
"pipeline" : [
{
"$lookup" : {
"localField" : "loginName",
"foreignField" : "userList.loginName",
"from" : "Site",
"as" : "User&Site"
}
},
{
"$unwind" : "$User&Site"
},
{
"$unwind" : "$User&Site.userList"
},
{
"$project" : {
"_id" : 0,
"userId" : "$_id",
"userRole" : "$User&Site.userList.role",
"siteId" : "$User&Site.id",
"active" : "$active",
"connectedAtTime" : "$connectedAtTime",
"lastMessageTime" : "$lastMessageTime"
}
}
]
})
但这不起作用。有人请告诉我是否可能。