我的文档具有属性docType,它根据每种类型的用途,在特定的案例模板或审计中将它们分开。但是,当我执行以下操作时:
document.getProperty("docType").equals("template");
document.getProperty("docType").equals("audit");
它们的结果始终相同,每次存储所有文档时都会返回,而不会通过docType过滤它们。
在下面,您可以检查查询功能。
public static Query getData(Database database, final String type) {
View view = database.getView("data");
if (view.getMap() == null) {
view.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
if(String.valueOf(document.get("docType")).equals(type)){
emitter.emit(document.get("_id"), null);
}
}
}, "4");
}
return view.createQuery();
}
任何提示?
这不是一种有效的方法。您的视图函数必须是纯的(它不能引用外部状态,如“类型”)。一旦创建了它,您就可以通过设置开始和结束键来查询它,或者只是一组键来过滤。