Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fix one error of Java The line 16 has errors, which is shown in picture package db.mongodb; import java.text.ParseException; import org.bson.Document; import com.mongodb.MongoClient; import com.mongodb.client.MongoDatabase;

Fix one error of Java

The line 16 has errors, which is shown in picture

image text in transcribed

package db.mongodb;

import java.text.ParseException;

import org.bson.Document;

import com.mongodb.MongoClient; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.IndexOptions;

// Create tables for MongoDB (all pipelines). public class MongoDBTableCreation { // Run as Java application to create MongoDB tables with index. public static void main(String[] args) throws ParseException { MongoClient mongoClient = new MongoClient(); MongoDatabase db = mongoClient.getDatabase(MongoDBUtil.DB_NAME);

// Step 1: remove old tables. db.getCollection("users").drop(); db.getCollection("items").drop();

// Step 2: create new tables, populate data and create index. db.getCollection("users") .insertOne(new Document().append("first_name", "John").append("last_name", "Smith") .append("password", "3229c1097c00d497a0fd282d586be050").append("user_id", "1111")); // make sure user_id is unique. IndexOptions indexOptions = new IndexOptions().unique(true);

// use 1 for ascending index , -1 for descending index // Different to MySQL, users table in MongoDB also has history info. db.getCollection("users").createIndex(new Document("user_id", 1), indexOptions);

// make sure item_id is unique. // Different to MySQL, items table in MongoDB also has categories info. db.getCollection("items").createIndex(new Document("item_id", 1), indexOptions);

mongoClient.close(); System.out.println("Import is done successfully."); } }

1 package db.mongodb; import java.text.ParseException; 4 5 import org.bson.Document; 6 7 import com.mongodb.MongoClient; 8 import com.mongo dbclie nt.MongoDatabase; 9 import com.mongodb.client.model.IndexOptions; 10 11 I/ Create tables for MongoDB (all pipelines) 12 public class MongoDBTableCreation { 13 / Run as Java application to create MongoDB tables with index. 14 public static void main(String[] args) throws ParseException 15 MongoClient mongoClientnew MongoClient); 16 MongoDatabase db -mongoClient.getDatabase (MongoDBUtil.DB NAME); 17 18 // Step 1: remove old tables 19 db.getCollection("users").drop); 20 db.getCollection("items").drop); 21 22 // Step 2: create new tables, populate data and create index. 23 24 25 26 27 28 29 // use 1 for ascending index, -1 for descending index 30 31 db.getCollection("users").createIndex (new Document("user_id", 1), indexOptions); 32 db.getCollection ("users") .insertOne (new Document).append("first_name", "John").append("last_name", "Smith") append("password", "3229c1097c00d497a0fd282d586be050").append("user_id", "1111")); // make sure user_id is unique IndexOptions indexOptions new IndexOptions().unique(true); /7 Different to MySQL, users table in MongoDB also has history info // make sure item_id is unique // Different to MySQL, items table in MongoDB also has categories info. db.getCollection("items").createIndex (new Document("item_id", 1), indexOptions); 35 36 mongoClient.close) System.out.println("Import is done successfully."); 38 R Markers Properties ServersData Source Explorer Snippets Console JU JUnit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Are there any questions that you want to ask?

Answered: 1 week ago