问题描述
我正在使用MongoDB 3.6.我正在尝试进行如下所示的汇总$ lookup.
I am working with MongoDB 3.6. I'm trying to do an aggregation $lookup as below.
$ lookup
{
from: 'm_mtr',
localField: 'mtdid',
foreignField: '_id',
as: 'mm'
}
这对我不起作用,因为'mtdid'是一个字符串,其值类似于'5bdbe5bcff10z046fcf8f04a',而'_id'是一个对象ID字段,其值类似于'ObjectId('5bdbe5bcff10z046fcf8f04a')'.
This doesn't work for me as 'mtdid' is a string with values like '5bdbe5bcff10z046fcf8f04a'and '_id' is an Object Id field with values like 'ObjectId('5bdbe5bcff10z046fcf8f04a')'.
是否可以将字符串转换为ObjectId?我知道这在Mongodb 4.0中是可能的.不幸的是,除了3.6,我别无选择.
Is there a way to convert string to ObjectId? I know this is possible in Mongodb 4.0. Unfortunately I don't have an option of using anything other than 3.6.
推荐答案
此MongoDB公开发行版于4.0发布,您必须尝试切换到4.0,因为它具有更多功能,并且由于迁移.
This a MongoDB open issue, which was released in 4.0, you must try switching to 4.0 since it has more features and of course there is no huge impact due to the migration.
https://jira.mongodb.org/browse/SERVER-22781
这篇关于MongoDB 3.6如何将字符串转换为对象ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!