查询日期类型的嵌套子文档并使用$ gte命令进行比较时遇到麻烦。
这是我的模式:
a: {
b: String,
c: String,
d: Date,
},
这是我的猫鼬查找查询:
SomeModel.find(
{ a: { $elemMatch: { d: { $elemMatch: { $exists: true } } } } }, callback);
当我在数据库中肯定有至少一个满足此要求的对象时,我什么也没得到。我猜我的语法是错误的
答案 0 :(得分:0)
使用dot notation-SELECT @Cols = STUFF((SELECT ',' +QUOTENAME(PRD_ValidDate)
FROM #Table
GROUP BY PRD_ValidDate
ORDER BY PRD_ValidDate
FOR XML PATH (''), Type).value('.','NVARCHAR(MAX)'),1,1,'')
SELECT @ColsWithNoNulls = STUFF((SELECT distinct ',ISNULL(' + QUOTENAME(PRD_ValidDate) + ', 0) ' + QUOTENAME(PRD_ValidDate)
FROM #Table
GROUP BY PRD_ValidDate
FOR XML PATH (''), Type).value('.','NVARCHAR(MAX)'),1,1,'')
SET @Query =
'
SELECT cardtype as [Card Type],' + @ColsWithNoNulls + ' FROM
(
SELECT ISNULL(CAST(Cardtype AS VARCHAR(30)),''TOTAL'') CardType, ISNULL(SUM (AllEntries),0) as AllEntries, PRD_ValidDate FROM #Table
GROUP BY cardtype, prd_Validdate
WITH CUBE
) src
PIVOT
( SUM(AllEntries)
For PRD_ValidDate IN ('+@Cols+')) piv
ORDER BY CASE WHEN (CardType=''TOTAL'')THEN 1 ELSE 0 END, CardType'