提问者:小点点

如何使用连接查询当使用NoSQL和node.js(express)像SQL连接?


如何使用连接查询当使用NoSQL和node.js(express)像SQL连接?

我想从两个表中提取数据。

>

  • 用户表:名称,用户ID

    POST表:标题,描述,用户ID

    我想要的结果:name,title,description

    我用的是云FireStore。

    感谢支持。。


  • 共1个答案

    匿名用户

    NoSQL不是关系型的

    NoSQL==无联接

    但我会告诉你一个方法,你可以做你想做的事。

    考虑到您的文档没有那个_id

    // Find the User First 
    
    UsersTable.findOne({userID: someuserID}).then((user)=>{
        // You now have the user Object, I hope your userID is unique (it is meant to be)
        //We find all the post by this user
        PostsTable.find({userID: user.userID}).then((posts)=>{
            // Now this posts object contains your array of all the post by the user
            console.log(posts)
        }
    }
    

    这就是NoSQL的方式。