首页 \ 问答 \ MongoDB查询工作但不支持Mongoose(MongoDB query work but not with Mongoose)

MongoDB查询工作但不支持Mongoose(MongoDB query work but not with Mongoose)

我正在尝试用Mongoose查询集合,有一个简单的db.course.find()查询的集合示例输出

{
  "_id" : ObjectId("581c9408fc01b15cb21043e4"),
  "calendar_id" : DBRef("calendar", ObjectId("581c5972fd1c59295c34f1b8"), "ecampus"),
  "date" : 1478473200000,
  "title" : "Conception et planification BI",
  "teacher" : "fiolet gilles",
  "start_at" : "08:30",
  "end_at" : "12:30"
}

我有一个运行良好的MongoDB查询

db.course.find({'calendar_id.$id': ObjectId("581c5972fd1c59295c34f1b8")}).sort({date: 1})

我试图用Mongoose做同样的查询,在我的NodeJS应用程序中我做了这个查询,但是这个返回一个空数组,因为ObjectId不正常。

let mongoose = require('mongoose');
let ObjectId = mongoose.Types.ObjectId;
let id = new ObjectId(session.calendar_id);

Course.find({'calendar_id.$id': id}).sort({date: 1}).exec(function (err, courses) {
    console.log(err, courses);
    createJsonBody(courses);
});

Course来自我的模型文件,就像这样

const Course = mongoose.model('course', {
    calendar_id: Schema.ObjectId,
    date: Number,
    title: String,
    teacher: String,
    start_at: String,
    end_at: String
});

如何使这个Mongoose查询起作用? 该模型可能没有正确形成?


I'm trying to query a collection with Mongoose, there is the collection sample output with a simple db.course.find() query

{
  "_id" : ObjectId("581c9408fc01b15cb21043e4"),
  "calendar_id" : DBRef("calendar", ObjectId("581c5972fd1c59295c34f1b8"), "ecampus"),
  "date" : 1478473200000,
  "title" : "Conception et planification BI",
  "teacher" : "fiolet gilles",
  "start_at" : "08:30",
  "end_at" : "12:30"
}

I have a MongoDB query that work well

db.course.find({'calendar_id.$id': ObjectId("581c5972fd1c59295c34f1b8")}).sort({date: 1})

I am trying to do the same query with Mongoose, in my NodeJS app I made this query but this one return an empty array because the ObjectId is not working well.

let mongoose = require('mongoose');
let ObjectId = mongoose.Types.ObjectId;
let id = new ObjectId(session.calendar_id);

Course.find({'calendar_id.$id': id}).sort({date: 1}).exec(function (err, courses) {
    console.log(err, courses);
    createJsonBody(courses);
});

Course is from my model file and is like this

const Course = mongoose.model('course', {
    calendar_id: Schema.ObjectId,
    date: Number,
    title: String,
    teacher: String,
    start_at: String,
    end_at: String
});

How can I make this Mongoose query to work ? The model is maybe not properly formed ?


原文:https://stackoverflow.com/questions/40842155
更新时间:2024-05-02 07:05

最满意答案

如果你想混合条形和线条,可以通过Timelion插件(从版本5开始包含在Kibana中)。 在Timelion选项卡中输入这样的内容:

.es(*).bars(),.es(*).lines()

你应该能够看到类似的东西:

情节

现在只需要进行您想要绘制的查询。

为了详细了解它,在右上角的Timelion选项卡上,您将看到一个选项卡 - 文档。 点击文档后,您将看到一个链接 - 转到教程。

尝试链接,它会引导您完成这些步骤。


If you want to mix bars and lines it's possible via the Timelion plugin (which is included in Kibana since version 5). Put something like this in the Timelion tab:

.es(*).bars(),.es(*).lines()

And you should be able to see something like:

Plot

Now it's just a matter of doing the query you want to plot.

For understanding it in detail, on Timelion tab, on top right corner, you will see a tab - Docs. Once you click on Docs, you will get a link - Go to Tutorial.

Try the link and it walks you through the steps.

相关问答

更多
  • 不幸的是,没有办法“配置”图表来实现你想要的。 这一切都与折线图比例绘图的工作方式有关。 这样说,你仍然可以通过使用一些“虚拟”数据来欺骗 chart.js来实现这种行为。 基本上,你创建一个“虚拟”的第一个和最后一个标签。 然后为您的条形数据数组添加一个对应的“虚拟”第一个和最后一个值(此数据永远不会显示)。 然后将相应的“虚拟”第一个和最后一个值添加到行数据数组中,但确保将该值设置为与下一个/ prev值相同,以直线结束(否则,您的线将在开始和结束处)。 这是我的意思。 var ctx = docume ...
  • 在“可视化”选项卡上,查询栏下方是您当前的索引模式。 就在这之下是指标。 你可能有“Y轴...计数”。 单击“Y轴”左侧的小箭头,然后从聚合下拉菜单中选择其他一些方法。 On the Visualize tab, just under the query bar is your current index pattern. Just under that are the metrics. You probably have "Y-Axis... Count". Click the little arrow ...
  • 尝试这个: fig, ax = plt.subplots() ax2 = ax.twinx() df4[['Date','Qty']].set_index('Date') \ .plot(kind='bar', ax=ax, color = 'dodgerblue', figsize=(13,4), ...
  • 我终于将我的多轴功能端口推到了这个前叉的主机上。 作为对发生的事情的一个非常简短的概述,我已经将一组轴添加到了该比例中。 每个轴都能够根据y自身的比例计算出一个值的位置。 开发人员现在唯一需要做的就是说每个数据集需要属于哪个轴组。 每个轴也可以被告知它应该是什么颜色以及它应该出现在图表的哪一侧。 如何使用它 - 在每个数据集中声明一个名为yAxesGroup的新属性 datasets: [{ label: "My First dataset", type: "bar", ...
  • 如果为2个折线图定义2个附加系列: // Series for line graphs var S4 = [46, 38, 48, 47]; var S5 = [33, 23, 38, 11]; 并确保除了S1,S2和S3之外还将它们作为参数传递: $.jqplot('graph_stacked', [S1, S2, S3, S4, S5], { 然后添加一个series对象,该对象定义要为每个系列使用的渲染器。 这里前3个使用BarRenderer ,后2个使用LineRenderer : se ...
  • 您可以使用StackedColumnLine图表类型,因为我认为没有StackedBarLine图表类型。 http://imgur.com/XdRk69I I have used Multi Axis chart and it is perfectly suit my needs.Muti-Axis chart provides a way to add more than one charts into one-chart.And we can Customize all added chart by ...
  • 我不认为它可能与primefaces: 在Primefaces中组合条形图和折线图 BTW密切关注它尚未出现的情节 (我不知道它是否会......)但似乎这是你正在寻找的确切的加法库...(与primefaces结合使用) 请注意: 你总是可以自己做,看看这个答案,它是使用外部图表库的一般方法在JSF中使用图表的一般方法 ,但它需要一些jquery / json技能 I dont think its possible with primefaces : Combining Bar and Line char ...
  • 问题1: 您在JSON中以此格式{'date': '10/1/2015', 'total': 900, 'percent': 1.0}日期,您需要将其转换为日期对象。 var format = d3.time.format("%d/%m/%Y"); data.forEach(function(d){ d.date = format.parse(d.date); }); 对于各种日期格式解析参考 Problem2: 您正在错误地定义域 var xScale = d3.time.scale() . ...
  • 使用数据文件Data.csv : 9.0447e-01 7.6771e-01 3.6151e-01 9.9169e-01 7.0212e-01 4.4109e-02 9.1423e-01 7.7540e-05 这个脚本: set boxwidth 0.6 relative set style fill solid plot "Data.csv" u 0:1 with boxes, "" u 0:2 with lines 你最终得到这个情节: 我希望这就是你要找的东西。 当然,还有很多人可 ...
  • 如果你想混合条形和线条,可以通过Timelion插件(从版本5开始包含在Kibana中)。 在Timelion选项卡中输入这样的内容: .es(*).bars(),.es(*).lines() 你应该能够看到类似的东西: 现在只需要进行您想要绘制的查询。 为了详细了解它,在右上角的Timelion选项卡上,您将看到一个选项卡 - 文档。 点击文档后,您将看到一个链接 - 转到教程。 尝试链接,它会引导您完成这些步骤。 If you want to mix bars and lines it's possi ...

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的