Skip to content

Commit 0c67f86

Browse files
authored
Create MongoModify.java
1 parent 4e21760 commit 0c67f86

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

mongodb/MongoModify.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.zetcode;
2+
3+
import com.mongodb.MongoClient;
4+
import com.mongodb.client.MongoCollection;
5+
import org.bson.Document;
6+
7+
import static com.mongodb.client.model.Filters.eq;
8+
9+
public class MongoModify {
10+
11+
public static void main(String[] args) {
12+
13+
try (var mongoClient = new MongoClient("localhost", 27017)) {
14+
15+
var database = mongoClient.getDatabase("testdb");
16+
17+
MongoCollection<Document> collection = database.getCollection("cars");
18+
19+
collection.deleteOne(eq("name", "Skoda"));
20+
collection.updateOne(new Document("name", "Audi"),
21+
new Document("$set", new Document("price", 52000)));
22+
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)