为什么mongodb不更新视图?

我尝试使mongodb视图(未实现)聚合来自嵌套对象的数据。

简化数据结构:

@Document(collection= "ObjectA")
class ObjectA {

  String id;
  String propA;
  List<ObjectB> list;

 }

class ObjectB {

  String name;
}

我创建了一个名为ObjectBView的视图,并首先将一个字段添加到了画中线。不幸的是,即使插入新的ObjectA之后,该视图也不包含数据。 集合ObjectBView存在于日志和mongo-connector中。在GUI中单击“查看”按钮后,它会返回错误提示:Collection not found!

这是我的代码:

    public void initMongoView() {
        if (!mongoTemplate.collectionExists("ObjectBView")) {

            MongoDatabase mongoDatabase = this.mongoClient.getDatabase(dbName);
            mongoDatabase.createView("ObjectBView","ObjectA",asList(buildViewProperties()));
            log.info(mongoTemplate.getcollectionNames().toString()); // <- view exists!
        }
    }

    private Document buildViewProperties() {
        Document pipeline = new Document("$project",new Document("propA",1));
        return pipeline;
    }

项目使用mongo-java-driver-3.11.2

为什么视图不包含数据?

guipingex 回答:为什么mongodb不更新视图?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2639308.html

大家都在问