Skip to content

createView succeeds but Java driver cannot immediately see or query the created view #476

Description

@lance6716

What happened?

I was running https://github.com/RenlySir/mongo-usage-report and found this problem. I have verified mongo:4.4 can pass this test

Steps to Reproduce

import com.mongodb.client.*;
import org.bson.Document;
import java.util.*;
import static com.mongodb.client.model.Aggregates.match;
import static com.mongodb.client.model.Filters.eq;

public class EloqViewProbe {
  public static void main(String[] args) throws Exception {
    String uri = args.length > 0 ? args[0] : "mongodb://127.0.0.1:39017";
    String dbName = args.length > 1 ? args[1] : "view_probe_java";
    try (MongoClient client = MongoClients.create(uri)) {
      MongoDatabase db = client.getDatabase(dbName);
      db.drop();
      db.createCollection("orders");
      db.getCollection("orders").insertMany(List.of(
        new Document("status", "paid").append("amount", 1),
        new Document("status", "new").append("amount", 2)));
      db.getCollection("orders_paid_view").drop();
      System.out.println("before names=" + db.listCollectionNames().into(new ArrayList<>()));
      db.createView("orders_paid_view", "orders", List.of(match(eq("status", "paid"))));
      List<String> names = db.listCollectionNames().into(new ArrayList<>());
      System.out.println("after names=" + names);
      System.out.println("list view=" + db.listCollections().filter(eq("name", "orders_paid_view")).into(new ArrayList<>()));
      System.out.println("view rows=" + db.getCollection("orders_paid_view").find().into(new ArrayList<>()));
      if (!names.contains("orders_paid_view")) throw new RuntimeException("orders_paid_view collection missing");
      System.out.println("PASS");
    }
  }
}

result

before names=[orders]
after names=[orders, system.views]
list view=[]
view rows=[]
Exception in thread "main" java.lang.RuntimeException: orders_paid_view collection missing

Environment

  • OS: linux
  • Version: eloqdoc master
  • Any other relevant details:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions