我要在OrientDB中插入具有嵌入式字段的记录,然后使用过滤器查询该记录:
insert into MyClass set embeddedField = {'@type': 'd', 'id': 1}
效果很好,
select from MyClass
返回我添加的记录。但是,当我为嵌入式字段添加带过滤器的位置时,没有任何结果:
select from MyClass where embdeddedField = {'@type': 'd', 'id': 1}
我认为这可能会发生,因为Orient在嵌入式文档中添加了@version字段,因此我尝试使用以下版本进行搜索:
select from MyClass where embdeddedField = {'@type': 'd', '@version': 0, 'id': 1}
但仍然没有结果。
问题:是否知道如何按整个文档过滤嵌入的字段?无需根据嵌入文档的每个字段进行明确过滤:
select from MyClass
where embdeddedField.id = 1
and embdeddedField.field2 = val2
and embeddedField.field3 = val3
由于多种原因,我想将整个对象作为单个查询参数传递:
select from MyClass where embdeddedField = ?
答案 0 :(得分:0)
那是因为提供的哈希已转换为嵌入式类。
也许看看ActiveOrientWiki https://github.com/topofocus/active-orient/wiki/Relations
说明:
上一个类def upload_passwd(self):
files = {'filename': '/root/Desktop/vdm/abhifile.txt'}
header = {
'Content-Type': "multipart/form-data"
}
self._request.headers.update(header)
response = self._request.post(operation='upload/passwd',
object_id=self.object_id, files=files)
,那里有两个属性的文档(无模式)
并添加现有文档
def upload_passwd(self):
f = open('/root/Desktop/vdm/abhifile.txt', 'rb')
header = {
'Content-Type': "multipart/form-data"
}
self._request.headers.update(header)
response = self._request.post(operation='upload/passwd', object_id=self.object_id,
data=f)
然后嵌入链接,记录看起来像
base
如果展开列表项,则可以查询“ @type”
如果您添加文档而没有摆脱,同样的事情也会发生
( 0..9 ).each do | b |
base_record= Base.create label: b, first_list: []
( 0..9 ).each {|c| base_record.first_list << FirstList.create( label: c ) }
end
INFO->CREATE VERTEX base CONTENT {"label":0,"first_list":[]}
INFO->CREATE VERTEX first_list CONTENT {"label":0}
INFO->update #136:0 set first_list = first_list || [#147:0] return after @this
如果省略类名,那么仅rid的更改范围
=> #<Base:0x00000000041a60e0 @metadata={:type=>"d", :class=>"base", :version=>11, :fieldTypes=>"first_list=z", :cluster=>129, :record=>1},
@attributes={:first_list=>["#149:1", "#150:1", "#151:1", "#152:1", "#145:2", "#146:2", "#147:2", "#148:2", "#149:2", "#150:2"], :label=>"1"}>
无论如何,对( 0..9 ).each {|c| base_record.first_list << FirstList.new( label: c ) }
20.04.(12:53:59) INFO->update #130:2 set first_list = first_list || [{ @type: 'd' ,@class: 'first_list' ,label: 0 }] return after @this
INFO->CREATE VERTEX base CONTENT {"label":"c","first_list":[]}
'#130:2'.expand
=> #<Base:0x00000000043927a0 @metadata={:type=>"d", :class=>"base", :version=>11, :fieldTypes=>"first_list=z", :cluster=>130, :record=>2},
@attributes={:first_list=>["#151:12", "#152:12", "#145:13", "#146:13", "#147:13", "#148:13", "#149:13", "#150:13", "#151:13", "#152:13"], :label=>"c"}>
的查询都会失败