- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 mongoDB,并且是 native 命令的新手,我喜欢使用别名作为字段名称
这里我使用两个表(公司和员工),在公司表中员工字段与多对一关联相关联
我的实际 JSON 如下。表一,名称为“公司”
comp_name : "YYYY",
employers : [
{
name : "Mike",
status : "Active",
id : 01
},{
name : "San",
status: "InActive",
id : 02
}
],
status : "Active",
id : 00001
表2及其名称为“employee”
{
name : "Mike",
status : "Active",
id : 01,
company : {
name : "YYYY",
status : "Active",
id : 00001
}
},
{
name : "San",
status: "InActive",
id : 02,
company : {
name : "YYYY",
status : "Active",
id : 00001
}
}
我可以使用命令获取公司表中的直接字段作为别名
Company.aggregate([
{$match:{}},
{$project:{c_name:"$comp_name",id:1}}
])
但我无法获取公司表中雇主中状态为“事件”的数据
我期望的 JSON 是,表一,名称为“公司”
c_name : "YYYY",
emp : [
{
n : "Mike",
st : "Active",
id : 01
}
],
st : "Active",
id : 00001
表2及其名称为“employee”
{
n : "Mike",
st : "Active",
id : 01,
comp : {
n : "YYYY",
st : "Active",
id : 00001
}
}
最佳答案
这将供您公司收藏
db.company.aggregate([
{ $match:{ status: "Active"} }, // to only get the documents that have ths status
{ $unwind: "$employers"}, // to flatten your array
{ $match:{ "employers.status": "Active"} }, // match again for active employers
{ $project: { // for the final structure
c_name: "$comp_name",
emp: ["$employers"],
st: "$status",
id: 1
}
}
])
关于javascript - mongoDB 中的字段名称别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47813986/
是的,我有这个对象,属性代表数据库表列作为属性,但它们都是大写的...如何将对象的所有属性更改为小写,而不将对象转换为将属性从大写转换为小写后的数组?..我想我可以用array_change_key_
是的,我有这个对象,属性代表db表的列作为属性,但是都是大写的...如何把对象的所有属性都变成小写,而不把对象转换成将属性从大写转换为小写后的数组?..我以为我可以用array_change_key_
我目前有一个论坛的 MySQL 帖子表。这包括父帖子和子帖子。如果它是父帖子,则它有一个主题。如果它是子帖子,则包含 parent_id。 例如: TABLE posts +----+--------
我正在添加一个临时表,其中包含第二个查询将使用的文件名列表。我知道文件名可以用于sql注入(inject),所以我想使用准备好的语句。 我的工作查询的简化版本如下所示(例如可能有 50 个文件名):
MySQL中查询所有数据库名和表名 查询所有数据库 ? 1
有人能给我指出正确的方向/网站吗 在 PHP 中有没有一种方法可以通过比较来自 FORM 的字段名称和来自数据库的 column_name 来动态更新特定的表。 例如 INPUT name="emai
获取表名及注释: ? 1
我正在使用 Pyshark 来解析 Wireshark 嗅探器日志,并且在使用“get_field_value”函数检索字段值时,我使用导出的 Json 格式文件(基于 pcapny 文件)来查找字段
我已经从以下 xsd 文件创建了 java bean 人.xsd
我用 MySQL 查询浏览器生成了一个 XML。我正在尝试应用 XSLT 将结果输出到 Word 表中。每条记录一张表。 这是我的 XML 示例 Critique
我有一个 select2 下拉列表,它配置为与远程数据一起使用。但是,我的远程数据源提供的搜索结果格式似乎与 select2 不兼容。远程数据例如是这样的: ... items: [ { value:
最好的 此时我在 python 2.7 中使用 Boto3,我想要的是:我的特定 DynamoDB 表的列标题。 此时,我正在处理一个非常大的 dynamoDB 表,有 80 列和 + 1.00O.0
错误信息 我刚刚试用了 Django-Rest-Framework 3.0 quickstart tutorial (伟大的介绍顺便说一句)并在我自己的系统/表上实现它时遇到了这个错误。 Improp
我正在尝试使用 haystack-whoosh 创建多个查询,我的最后一个问题是通过放置双反斜杠解决的,但现在出现了一个新错误。我在命令提示符中收到以下错误: C:\Users\varun\De
在尝试更新文档时,我在字段 timesToDisplay 中收到上述错误。 MongoDB 版本 2.6.7。 整个模型: msg = { 'name': '',
我是一名优秀的程序员,十分优秀!