如何使用Mongodb Java驱动程序:
db.products.insert({
"id":nextValue("productIdSequence"),
"product_name":"Apple iPhone",
"category":"mobiles"
});
以下不执行存储在服务器中的JS:
Document document = toDocument(object);
StringBuffer sb = new StringBuffer().append("nextValue(\'").
append("productIdSequence").
append("\')");
BsonJavaScript sequenceFunction = new BsonJavaScript(sb.toString());
document.append("id", sequenceFunction);
database.getCollection("products").insertOne(document);