课程: Vue.js: Creating and Hosting a Full-Stack Site

今天就学习课程吧!

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

Loading individual products from MongoDB

Loading individual products from MongoDB

- Alright, so we've added MongoDB to two of our three load endpoints. So the last thing that we're going to do here is see how to add MongoDB to our endpoint for loading individual product data. So what this is going to look like it's going to be very similar to what we've seen elsewhere. We're going to start off by connecting to MongoDB and selecting the database. So I'm just going to copy those lines from our cart endpoint and paste them inside here. And then of course, we're also going to need to add the async keyword to our callback function. And now that we've done that, what we're going to do is after we get the product ID from the URL parameter instead of finding the product in our array which was the old way of doing things when we were still storing our database in a file, we're going to say const product equals and then we'll say await db.collections. And that's going to be product and actually it's not…

内容