java9_List.of

java9引入 List.of("a","b"); 生成一个List<String> 后 元素就是不可变的了 如果再增加list中的元素就会报错

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Here's an example Java code to execute the given MongoDB aggregation query: ``` import com.mongodb.client.AggregateIterable; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; import org.bson.Document; import java.util.Arrays; public class MongoAggregationExample { public static void main(String[] args) { // Create MongoDB client MongoClient mongoClient = MongoClients.create("mongodb://localhost:27017"); // Get reference to the database MongoDatabase database = mongoClient.getDatabase("yourDatabaseName"); // Build the aggregation pipeline AggregateIterable<Document> result = database.getCollection("website_sort").aggregate(Arrays.asList( new Document("$match", Filters.eq("websiteCategoryId", "63c27b11d5957b16c46dc17e")), new Document("$project", new Document("id", new Document("$toObjectId", "$websiteListId"))), new Document("$lookup", new Document("from", "website_list_cs") .append("localField", "id") .append("foreignField", "_id") .append("as", "B_list")), new Document("$project", new Document("id", 1) .append("B_list.title", 1) .append("B_list.desc", 1) .append("B_list.labels", 1) .append("B_list.link", 1) .append("B_list.logo", 1) .append("B_list.vpn", 1) .append("B_list.snapshot", 1) .append("B_list.recommend", 1) .append("B_list.vpn", 1) .append("B_list.status", 1)), new Document("$sort", new Document("id", 1)) )); // Print the result for (Document doc : result) { System.out.println(doc.toJson()); } // Close the MongoDB client mongoClient.close(); } } ``` Make sure to replace "yourDatabaseName" with the name of your actual database. Also, don't forget to add the necessary MongoDB Java driver to your project's dependencies.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值