我正在寻找一种解决方案,在mongodb java spring框架中使用null dbref保存对象.请考虑以下示例:
@Document
public class A {
@Id
private String id;
@DBRef
private B b;
public A() {
this.b = null;
}
...
}
@Document
public class B {
@Id
private String id;
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我实例化A,即A a = new A();通过存储库将此对象保存到mongodb,即aRepo.save(a).然后,我有以下例外:
org.springframework.data.mapping.model.MappingException: Cannot create a reference to an object with a NULL id.
Run Code Online (Sandbox Code Playgroud)
有没有办法用null dbref保存对象?
谢谢你的帮助!
按照MongoDB的文档,"Queries cannot use both text and Geospatial Indexes"意味着我们不能同时使用$textSearch,并$nearSphere在单个弹簧数据蒙戈库方法.
但我正在寻找一些解决方法,这将允许我使用两者TextCriteria并nearSphere Pint一起使用,我没有其他方式,我真的想让这个工作.
我找到了https://groups.google.com/forum/#!msg/mongodb-user/pzlYGKMYMVQ/O6P5S578Xx0J,表示他能够执行一些解决方法,但我没有得到他如何编写Repository方法来跟踪查询?
find({"add.loc": {$near:{$geometry: {type: "Point",coordinates:
[116.425, -31.09]}, $maxDistance: 500000}},$text:{$search: "hello"}}
Run Code Online (Sandbox Code Playgroud)
我处境最糟糕
对于我的存储库方法,它给出:
Page<User> getAddress_PositionNear(TextCriteria tc,Point gpoint, Distance d, Pageable p);
"errmsg" : "text and geoNear not allowed in same query" , "code" : 2
Run Code Online (Sandbox Code Playgroud)