Build Applications with Meteor by Dobrin Ganev
Author:Dobrin Ganev
Language: eng
Format: epub, pdf
Publisher: Packt Publishing
Published: 2017-05-29T09:14:04+00:00
Importing the data
They are many ways of importing existing data into MongoDB. It depends on many factors, but the two most important ones are the source and data model. Our data sample is in JSON format, which is the format of the documents stored in MongoDB collections. The way MongoDB works is that behind the scenes, it encodes the JSON documents in a binary format—BSON (Binary JSON)—with some additional metadata, and when we query the collections, we get plain JSON objects. JSON is what we, JavaScript developers, naturally think of data that makes MongoDB extremely easy to work with; this is also the main reason why it is one of the most popular NoSQL databases.
How we model our collections is completely different from how we'd model our tables in a relational database. Data modeling in MongoDB is a big topic and it's out of the scope of this book; however, we actually did a bit of data modeling in our Redux stores in the previous chapters. We started modeling our stores with the question, "what state our application needs to persist?" and the way we think in MongoDB is, "what data does our application UI need?" In both cases, we start data modeling from the UI, which is the opposite of how we would usually do data modeling in relational databases.
For this app, we can do a direct import of the sample JSON dataset into one collection and build our frontend on the defined model, which is fine for the purpose of learning the full-text search topic.
First, let's create the app and launch the mongo shell from the app directory:
>> meteor create search
We need to keep our app running in order to launch the shell. Open another terminal and change the directory to the root of the app, then execute the following command:
>> meteor mongo
If the app is running, it will return the MongoDB version and the connection to the database instance:
MongoDB shell version: 3.2.6
connecting to: 127.0.0.1:3001/meteor
The next step of importing the data is to save it as a JSON file on the disk. We can use the same name as that of the data from the primer-dataset.json link. Copy and paste the data from the link: https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/primer-dataset.json into the file. Importing data with the MongoDB import tool is a straightforward task. Note that you need to execute it outside the Meteor mongo shell. Launch another terminal and execute the command:
mongoimport -h localhost:3001 —db meteor —collection restaurants —type json —file ~/chapter_six/search/primer-dataset.json
The first argument (-h) is the hostname of the database where we need to connect (localhost:3001). The database's name is meteor (the default name when we created the app). We then specify where we want to import the data (the restaurants collection); the data type is JSON and the last argument is the path of the file. If you have never had MongoDB installed outside a Meteor project, you may get an error if you run the tool. To fix this, you need to install the mongo-clients package:
>>sudo apt install
Download
Build Applications with Meteor by Dobrin Ganev.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8298)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6845)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6575)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6445)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6414)
Kotlin in Action by Dmitry Jemerov(5063)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4317)
Functional Programming in JavaScript by Mantyla Dan(4038)
Solidity Programming Essentials by Ritesh Modi(4005)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3798)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3741)
The Ultimate iOS Interview Playbook by Avi Tsadok(3714)
