在MongoDB中存储动态值,该值指的是其他属性
我在节点JS -MongoDB工作。我有一个要求,我需要在MongoDB中存储和检索数据,这些数据是动态的,并指代集合中的其他键。 例子: firstName:字符串 lastname:字符串, fullname:字符串
假设我们插入像下面的记录
{ firstName:“你好”, 姓:“世界”, fullname:“名称lastname” }
现在,当我们检索记录时,将有望显示实际名称。在前端,我们可以使用字符串插值之类的东西以角度实现。有什么办法可以在后端直接处理此表达式。我的实际用例涉及更复杂的结构,因此不可能依靠前端。
I am working in Node js - mongoDB . I have a requirement where I need to store and retrieve data in mongoDB which are dynamic and refers to other keys in the collection.
Example:
firstName : string
lastName : string,
fullName : string
Assume we insert a record like below
{
firstName : "hello",
lastName : "world",
fullName : " firstName lastName"
}
Now when we retrieve the record the fullName field is expected to show the actual name . In front end , we could use something like string interpolation to achieve this in angular. Is there any way I can directly handle this expression in backend . My actual use case involves more complex structures hence it is not possible to rely on front end.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mongo聚合可以用于执行此操作:
这将返回带有全名字段的文档。
Mongo聚集可用于使构建的运算符量=)使更复杂的查询。
Mongo aggregations can be used to do this :
This will return a document with a fullName field.
Mongo aggregation can be used to make way more complex queries with the amount of operators builded in =)