Page 1 of 1

Mongoclient kann nicht auf einen Typ gelöst werden

Posted: 17 Aug 2025, 01:00
by Anonymous
Ich bin neu bei MongoDB und ich möchte eine Verbindung zu meinem Mongod -Server herstellen.

Code: Select all

import com.mongodb.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Dining {

public static void main(String[] args) {
Lock forks[] = new ReentrantLock[5];

try {
MongoClient mongoClient = new  MongoClient("mongo");
System.out.println("Connection to mongodb successful.");
DB db = mongoClient.getDB( "mydb" );
System.out.println("Database 'mydb' created.");
DBCollection coll = db.createCollection("mycol", null);
System.out.println("Collection 'mycol' created.");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

for(int i = 0; i