Domanda

I'm using Jongo to query mongodb. The problem is that when I try to add items to an array field I get the error that says

HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: {$addToSet:{bodyParameters:[ { "first" : { "weight" : 1.0 , "height" : 2.0 , "waist" : 3.0 , "biceps" : 4.0 , "chest" : 5.0 , "forearm" : 6.0 , "wrist" : 7.0 , "neck" : 8.0 , "hip" : 9.0 , "buttocks" : 10.0 , "shin" : 11.0} , "second" : "20130609"}]} cannot be parsed

My method looks that way

public void updateBodyParameters(Profile profile) {
        getCollection().update("{_id:#}", profile.getUsername()).with(
                "{$addToSet:{bodyParameters:#}", profile.getBodyParameters()
        );
    }

Body parameters is a class containing this

public class Tuple<E, T> implements Serializable {
private E first;
private T second;

And it is created as

ArrayList<Tuple<BodyParameters, String>>

and the BodyParameters class contains fields

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;

Tell me please what's the problem with update

È stato utile?

Soluzione

You're missing a closing curly brace, it should be:

"{$addToSet:{bodyParameters:#}}", profile.getBodyParameters()

Note that there should be two closing braces after the #.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top