使用JADE和mongoose对象时出错

Error while using JADE and mongoose objects

本文关键字:出错 对象 mongoose JADE 使用      更新时间:2023-09-26

我在渲染一个jade模板时遇到问题,我想在该模板中传递一个数组变量,其中包含ObjectId(fmor Mongo)的对象

{ name: 'fake',
  slug: 'FAKE',
  address: 'fake',
  city: 'Madrid',
  country: 'Spain',
  _owner: 51f65388f98a405469000003,
  _id: 51f65389f98a405469000007}

这是执行#{objects}时的表示。

很明显,这会导致代币违法。。。我怎么能在不打碎任何东西的情况下把这些变量插入玉石中呢。

看起来是由于缺少引号,在传递到模板之前,应该将_owner和_id转换为字符串。

{ 
  name: 'fake',
  slug: 'FAKE',
  address: 'fake',
  city: 'Madrid',
  country: 'Spain',
  _owner: '51f65388f98a405469000003', // convert to string
  _id: '51f65389f98a405469000007'     // convert to string
}

在猫鼬中,你可以进行

obj._owner.toHexString();
obj._id.toHexString();