且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mongodb 相当于 sql select 'longfield' as 'a'

更新时间:2022-03-18 04:34:22

最常见的方法是在您的应用程序中创建一个映射层来接收一组字段,然后将它们映射到您的应用程序需要的内容.

The most common approach is to make a mapping layer in your application to take in a set of fields and then map them to what your application needs.

您说得对,MongoDB 中根本没有内置 AS 投影.

You are correct that there is not AS projection built into MongoDB at all.

我相信您可以通过聚合来实现这一点:

I believe you could accomplish this with the aggregation however:

  • 我不明白为什么
  • 与仅在应用中进行相比,它会更重、更慢.

所以是的,我会坚持在应用程序中编写映射类.

So yea, I would stick to writing a mapping class in the app.