Here you can find the source of dbObjectFromMap(Map
public static BasicDBObject dbObjectFromMap(Map<String, Object> from)
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.util.Map; import java.util.Map.Entry; import javax.script.Bindings; import com.mongodb.BasicDBList; import com.mongodb.BasicDBObject; import jdk.nashorn.api.scripting.JSObject; public class Main { public static BasicDBObject dbObjectFromMap(Map<String, Object> from) { BasicDBObject result = new BasicDBObject(); for (Entry<String, Object> entry : from.entrySet()) { result.append(entry.getKey(), convert(entry.getValue())); }//from w w w. j a v a2s. co m return result; } @SuppressWarnings("unchecked") private static Object convert(Object from) { if (from instanceof JSObject) { if (((JSObject) from).isArray()) { return convertArray((Bindings) from); } } if (from instanceof Map) { return dbObjectFromMap((Map<String, Object>) from); } return from; } private static BasicDBList convertArray(Bindings from) { BasicDBList list = new BasicDBList(); for (int i = 0; i < from.size(); i++) { list.add(from.get(String.valueOf(i))); } return list; } }