Mongodb graphQL 和 Feather js 数据通过 _id 获取 return 在某些情况下为 null

Mongodb graphQL and Feather js data fetch by _id return null for some case

我正在尝试根据 mongoDB 中的 _id 获取记录,在 mongoDB 控制台中它工作正常,但是当我尝试在 GraphQL 和 Feather js 中实现相同的代码时,它 return 为空,未找到记录,但记录在数据库中。如果我将值更改为 507F191M810c19729De860eA 是 return 记录。它适用于一些值。这是一个很奇怪的问题。

Locations.find(
      { 
        query: 
        { 
          _id: "2313891acb3420defAFadefc" 
        }
      }
    ).then(function(result){
      console.log(result)
    }

请尝试通过转换为 objcectId 来查找 mongoId。您将 id 作为简单字符串传递。可能是你没有得到数据。

var ObjectID = require('mongodb').ObjectID;

现在您可以将字符串转换为mongo的id。

Locations.find(
  { 
    Query: 
    { 
      _id: ObjectID("2313891acb3420defAFadefc") 
    }
  }
).then(function(result){
  console.log(result)
}