I’m trying to use the java connector to create a link between two tables
mongoClient = MongoClients.create(uri);
db = mongoClient.getDatabase("testing");
MongoCollection<Document> hobby = db.getCollection("hobby");
hobby.drop();
InsertOneResult gaming = hobby.insertOne(new Document("name", "gaming"));
InsertOneResult running = hobby.insertOne(new Document("name", "running"));
MongoCollection<Document> coll = db.getCollection("coll");
coll.drop();
coll.insertMany(
Arrays.asList(
new Document("name", "Max").append("age", 24).append("hobby_id", gaming.getInsertedId()),
new Document("name", "Alex").append("age", 25).append("hobby_id", gaming.getInsertedId()),
new Document("name", "Claire").append("age", 19).append("hobby_id", running.getInsertedId()))
);
As you can see, it detects the hobby_id as an objectId, but doesn’t link the tables together.
Is there some other way to do this without using POJO?