课程: React: Creating and Hosting a Full-Stack Site (2022)

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Rewriting your upvote endpoint

Rewriting your upvote endpoint

- All right, so now that we've created this endpoint for loading article info from MongoDB, the next thing that we're going to need to do is go through and modify our up voting endpoint and our comments endpoint to use MongoDB instead of that fake in-memory database which they're currently referencing that no longer exists, right? So this is actually going to be pretty straightforward. All we're really going to need to do is replace this line where we say articles info dot find with an actual query to MongoDB. Now, the setup code here, right? The code for connecting to MongoDB is going to be pretty much the same as what we saw up here in our get article endpoint. So just to go through that again, what we're going to need to do is use Mongo client to connect to MongoDB. And that's going to look like this. We'll say "const client equals new Mongo client" and then we'll have the URL, which again is going to be "MongoDB…

内容