运行 本机 mongodb 查询 mongodb java 驱动程序
Run native mongodb query with mongodb java driver
我想使用 java 执行 CRUD 操作,例如 updateOne()
、updateMany()
或 deleteMany()
等。但是当我想 运行 使用像这样的运算符时$set
、$unset
我必须像 Updates
一样导入新的 类 或创建嵌套的 Document
对象。我想插入 JSON 查询作为本机 Mongodb 使用。前任:
myCollection.updateOne(Json_String_filter,Query_with_operoters_like_$set_as_Json_string);
使用 org.bson.Document
中的 Document.parse(String json)
。它 returns 文档对象。这是来自 Official MongoDb tutorial.
的示例
原文:
{
$set: { "size.uom": "cm", status: "P" },
$currentDate: { lastModified: true }
}
您可以 运行 在 java 中作为:
collection.updateMany(new Document(),Document.parse("{\n" +
" $set: { \"size.uom\": \"cm\", status: \"P\" },\n" +
" $currentDate: { lastModified: true }\n" +
" }"));
我想使用 java 执行 CRUD 操作,例如 updateOne()
、updateMany()
或 deleteMany()
等。但是当我想 运行 使用像这样的运算符时$set
、$unset
我必须像 Updates
一样导入新的 类 或创建嵌套的 Document
对象。我想插入 JSON 查询作为本机 Mongodb 使用。前任:
myCollection.updateOne(Json_String_filter,Query_with_operoters_like_$set_as_Json_string);
使用 org.bson.Document
中的 Document.parse(String json)
。它 returns 文档对象。这是来自 Official MongoDb tutorial.
原文:
{
$set: { "size.uom": "cm", status: "P" },
$currentDate: { lastModified: true }
}
您可以 运行 在 java 中作为:
collection.updateMany(new Document(),Document.parse("{\n" +
" $set: { \"size.uom\": \"cm\", status: \"P\" },\n" +
" $currentDate: { lastModified: true }\n" +
" }"));