【发布时间】:2022-05-10 15:44:59
【问题描述】:
我想通过它的_id 来获取记录,如下所示:
db.user.find({_id : ObjectId("53a095aa4568cb1fef93f681")})
如您所见,记录存在:
我认为我的方法是正确的:
- Why am I unable to find a record by _id in mongodb
- how do I search for an object by its ObjectId in the console?
- Is it ok to use Mongo's "Object ID" as its unique identifier? If so, how can I convert it to a string and look it up by string?
那么我的代码有什么问题?我正在使用 RoboMongo。
【问题讨论】:
-
正如下面回答的那样,您插入文档时没有使用默认的 MongoDB ObjectId 类型,可能是您的代码中的错误或其他问题
标签: mongodb