|
38 | 38 | "// Import the MongoDB Driver using Maven\n", |
39 | 39 | "%maven org.mongodb:mongodb-driver-sync:5.0.0\n", |
40 | 40 | " \n", |
41 | | - "import com.mongodb.client.*;\n", |
42 | | - "import org.bson.Document;\n", |
43 | | - "import org.bson.json.JsonWriterSettings;\n", |
44 | | - "import java.util.ArrayList;\n", |
45 | | - "import java.util.List;\n", |
| 41 | + "import com.mongodb.client.MongoClient;\n", |
| 42 | + "import com.mongodb.client.MongoClients;\n", |
| 43 | + "import com.mongodb.client.MongoDatabase;\n", |
| 44 | + "import com.mongodb.client.MongoCollection;\n", |
| 45 | + "import com.mongodb.client.FindIterable;\n", |
| 46 | + "import com.mongodb.client.model.IndexOptions;\n", |
| 47 | + "import com.mongodb.client.model.Indexes;\n", |
46 | 48 | "import com.mongodb.MongoCommandException;\n", |
47 | 49 | "\n", |
| 50 | + "import static com.mongodb.client.model.Filters.eq;\n", |
| 51 | + "import static com.mongodb.client.model.Filters.gt;\n", |
| 52 | + "import static com.mongodb.client.model.Filters.and;\n", |
| 53 | + "\n", |
| 54 | + "import org.bson.Document;\n", |
| 55 | + "import org.bson.conversions.Bson;\n", |
| 56 | + "\n", |
48 | 57 | "// Set your connection String\n", |
49 | 58 | "String connectionString = \"mongodb://admin:mongodb@localhost:27017/\";\n", |
50 | 59 | "\n", |
|
108 | 117 | }, |
109 | 118 | "outputs": [], |
110 | 119 | "source": [ |
111 | | - "import static com.mongodb.client.model.Filters.*;\n", |
112 | | - "import org.bson.conversions.Bson;\n", |
113 | | - "\n", |
114 | 120 | "Bson hundredPages = eq(\"pages\", 100);\n", |
115 | 121 | "Bson after2008 = gt(\"year\", 2008);\n", |
116 | 122 | "Bson booksWrittenAfter2008WithOneHundredPages = and(hundredPages, after2008);\n", |
|
147 | 153 | }, |
148 | 154 | "outputs": [], |
149 | 155 | "source": [ |
150 | | - "import static com.mongodb.client.model.Filters.*;\n", |
151 | | - "import org.bson.conversions.Bson;\n", |
152 | | - "\n", |
153 | 156 | "Bson hundredPages = eq(\"pages\", 100);\n", |
154 | 157 | "Bson after2008 = gt(\"year\", 2008);\n", |
155 | 158 | "Bson booksWrittenAfter2008WithOneHundredPages = and(hundredPages, after2008);\n", |
|
181 | 184 | }, |
182 | 185 | "outputs": [], |
183 | 186 | "source": [ |
184 | | - "import com.mongodb.client.model.IndexOptions;\n", |
185 | | - "import com.mongodb.client.model.Indexes;\n", |
186 | | - "\n", |
187 | 187 | "try {\n", |
188 | 188 | " // drop the index\n", |
189 | 189 | " books.createIndex(Indexes.compoundIndex(Indexes.ascending(\"pages\"), Indexes.ascending(\"year\")));\n", |
|
213 | 213 | }, |
214 | 214 | "outputs": [], |
215 | 215 | "source": [ |
216 | | - "import static com.mongodb.client.model.Filters.*;\n", |
217 | | - "import org.bson.conversions.Bson;\n", |
218 | | - "\n", |
219 | 216 | "Bson hundredPages = eq(\"pages\", 100);\n", |
220 | 217 | "Bson after2008 = gt(\"year\", 2008);\n", |
221 | 218 | "Bson booksWrittenAfter2008WithOneHundredPages = and(hundredPages, after2008);\n", |
|
252 | 249 | }, |
253 | 250 | "outputs": [], |
254 | 251 | "source": [ |
255 | | - "import static com.mongodb.client.model.Filters.*;\n", |
256 | | - "import org.bson.conversions.Bson;\n", |
257 | | - "\n", |
258 | 252 | "Bson hundredPages = eq(\"pages\", 100);\n", |
259 | 253 | "Bson after2008 = gt(\"year\", 2008);\n", |
260 | 254 | "Bson booksWrittenAfter2008WithOneHundredPages = and(hundredPages, after2008);\n", |
|
0 commit comments