[英]How to add items to Mongo array using Jongo?
我正在使用Jongo查詢mongodb。 問題是,當我嘗試將項目添加到數組字段時,出現錯誤提示
HTTP狀態500-請求處理失敗; 嵌套的異常是java.lang.IllegalArgumentException:{$ addToSet:{bodyParameters:[{“ first”:{“ weight”:1.0,“ height”:2.0,“腰圍”:3.0,“ biceps”:4.0,“ chest” :5.0,“ forearm”:6.0,“ wrist”:7.0,“ neck”:8.0,“ hip”:9.0,“臀部”:10.0,“ shin”:11.0},“ second”:“ 20130609”}]}無法解析
我的方法看起來像那樣
public void updateBodyParameters(Profile profile) {
getCollection().update("{_id:#}", profile.getUsername()).with(
"{$addToSet:{bodyParameters:#}", profile.getBodyParameters()
);
}
身體參數是包含此參數的類
public class Tuple<E, T> implements Serializable {
private E first;
private T second;
它被創建為
ArrayList<Tuple<BodyParameters, String>>
並且BodyParameters類包含字段
private double weight;
private double height;
private double waist;
private double biceps;
private double chest;
private double forearm;
private double wrist;
private double neck;
private double hip;
private double buttocks;
private double shin;
告訴我更新有什么問題
您缺少右花括號,應該是:
"{$addToSet:{bodyParameters:#}}", profile.getBodyParameters()
請注意,在#后面應有兩個右花括號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.