(MongoDB Java) $push into array

后端 未结 5 587

I\'m using mongo 2.2.3 and the java driver. My dilemma, I have to $push a field and value into an array, but I cant seem to figure out how to do this. A sample of my data:<

5条回答
  •  执笔经年
    2020-11-28 10:20

    If you're more comforable with the query format of the shell, you may find it's easier to use JSON.parse to contstruct your DBObject for the $push:

    import com.mongodb.util.JSON;
    
    String json = "{$push:{scores:{type:'quiz', score:99}}}";
    DBObject push = (DBObject) JSON.parse(json);
    

提交回复
热议问题