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 thisconst 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
最满意答案
如果你想混合条形和线条,可以通过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:
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 ...
-
如何在一个图表中显示堆栈条形图和折线图?(How can i show Stack Bar chart and line chart both in one chart? [duplicate])[2022-03-09]
您可以使用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 ...