MongoDB查询以从ObjectId转换为String
在MongoDB中使用toString()将ObjectId转换为字符串。让我们创建一个包含文档的集合
> db.demo52.insertOne({"StudentName":"Chris"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e27129bcfb11e5c34d89910")
}> db.demo52.find();
{ "_id" : ObjectId("5e27129bcfb11e5c34d89910"), "StudentName" : "Chris" }> ObjectId("5e27129bcfb11e5c34d89910").toString();
ObjectId("5e27129bcfb11e5c34d89910")现在可以检查ObjectId是否为字符串
> typeof ObjectId("5e27129bcfb11e5c34d89910").toString();String