我了解了如何使用 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"
}
}
]
})
但这不起作用。有人请告诉我这是否可能。