[英]querying couchbase with spring-data-couchbase, using multiple columns
I am using couchbase3 with spring-data-couchbase , and want to query data using spring data repository with multiple columns.我将 couchbase3 与spring-data-couchbase 一起使用,并希望使用具有多列的 spring 数据存储库查询数据。
public interface UserAccountRepository extends CrudRepository<UserAccount, Long> {
public UserAccount findByEmail(Query eMail);
public UserAccount findByEmailAndStatus(Query query); // fn with multiple column, but not getting the result
}
How should I write Map function and Reduce function for the same?我应该如何编写 Map 函数和 Reduce 函数?
For the function findByEmail(Query eMail);对于函数findByEmail(Query eMail); to work, I have added the view with Map fn()
为了工作,我添加了带有 Map fn() 的视图
function (doc, meta) {
emit(doc.email,doc);
}
This view have email as key, and value is the document.此视图以电子邮件为键,值为文档。 But if i need to query using email and status?
但是如果我需要使用电子邮件和状态查询? How should the view look like ?
视图应该是什么样子的?
I have seen this link, but not very clear.我看过这个链接,但不是很清楚。 https://stackoverflow.com/questions/28938755
https://stackoverflow.com/questions/28938755
您可以在此处的文档中使用像描述一样的复合键: http : //docs.couchbase.com/developer/dev-guide-3.0/compound-keys.html
I was able make springdata function to invoke a compound Key view.我能够使 springdata 函数调用复合键视图。 My Document name is : Data Compound Key View
我的文档名称是:数据复合键视图
function (doc, meta) {
if(doc && doc._class == "com.couchbase.entity.Data"){
emit([doc.key1, doc.key2], doc);
}
}
SpringData Repository Inferface shown below : SpringData Repository 接口如下所示:
package com.couchbase.repository;
import java.util.List;
import org.springframework.data.couchbase.core.view.View;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import com.couchbase.client.protocol.views.Query;
import com.couchbase.entity.Data;
public interface DataRepository extends CrudRepository<Data, String> {
@View(designDocument="Data",viewName="findByKey1AndKey2")
public List<Data> findByKey1AndKey2(Query query);
}
Test Class shown below :测试类如下所示:
import com.couchbase.client.protocol.views.ComplexKey;
import com.couchbase.client.protocol.views.Query;
public class DataTest extends WebAppConfigurationAware{
@Autowired
private DataRepository dataRepository;
@Test
public void testStringDataCompoundQuery(){
Object[] objArr = new Object[2];
objArr[0] = "aaa";
objArr[1] = 1;
Query query = new Query();
query.setKey(ComplexKey.of(objArr));
System.out.println(dataRepository.findByKey1AndKey2(query));
}
}
If this was useful for you, please up vote如果这对您有用,请投票
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.