MongoDB java 驱动程序:按 id 过滤

编程入门 行业动态 更新时间:2024-10-28 19:30:46
本文介绍了MongoDB java 驱动程序:按 id 过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用最新版本的 MongoDB 的 Java 驱动程序.不幸的是,搜索后我无法通过 _id 过滤...

I use the latest version of the Java Driver of MongoDB. Unfortunately after searching I am not able to filter by an _id ...

我尝试了很多东西:

_id id_objet = new _id(); id_objet.set$oid(idobjet); Document myDoc = collection.find(eq("_id", id_objet)).first();

我对 Grizzly 的请求错误...

I got a bad request error with Grizzly ...

使用最新版本的驱动程序按_id过滤的正确方法是什么?

What is the proper way to filter by _id with the latest version of the driver ?

感谢您的帮助

推荐答案

终于没什么大不了的 :

It was finally not a big deal :

Document myDoc = collection.find(eq("_id", new ObjectId(idobjet))).first();

您必须使用 ObjectId(id).

You have to use ObjectId(id).

更多推荐

MongoDB java 驱动程序:按 id 过滤

本文发布于:2023-11-22 18:59:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618618.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:驱动程序   MongoDB   java   id

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!