2016-02-24 46 views
0

我試圖讓多值字段應該只存儲唯一值。 當我試圖使用部分更新(原子更新使用「添加」)添加值。 如果該值已經存在於多值字段中,則不應該增加值。如何在多值字段中添加/存儲唯一值?

For example: 
<field name="name" type="text_general" indexed="true" stored="true" multiValued="true"/>  

first adding values into field : 
{"id":"36", 
"name":["RAJEEV CHAUHAN","Alex"] 
} 
Now values in the "name" field are as follows"name":["RAJEEV CHAUHAN","Alex"]. 


second time when I add using partial update "add" as below, 
{"id":"36", 
"name":{"add":["RAJEEV CHAUHAN","Alex","ERICK"]} 
} 
Now the values in the field should be "name":["RAJEEV CHAUHAN","Alex","ERICK"], it should not be 
"name":["RAJEEV CHAUHAN","Alex","RAJEEV CHAUHAN","Alex","ERICK"] 

How can I achieve these functionality? 

Thanks in advance 

回答

0

你想要做的是不可能的。你會更好地閱讀客戶端的值,並使用「set」命令而不是「add」來發布更新 - 例如。

{ "id": "36", 
    "name": { "set": [ "RAJEEV CHAUHAN","Alex","ERICK" ] } 
} 
相關問題