簡體   English   中英

為什么我不能在Node中運行這個MongoDB查詢,但它在社區羅盤中工作?

[英]Why can't I run this MongoDB query in Node, but it works in community compass?

我試圖從我的節點應用程序運行這個MongoDB查詢,我試圖查詢具體的日期。

到目前為止,我試過這個:

    x = await dbo.collection("master").find({Process: "Process1"}).toArray();

    x = x.map(o => o.Finish_Time);

    xtime= recent_time(x) //function finds the maximum time in an array

    console.log(xtime) //returns '2019-06-12T08:05:33.000Z'

    query_result = await dbo.collection("master").find({Finish_Time: xtime}).map(o => o.Shortnum);

簡而言之,所有這些查詢都是為Process1拉取所有日期,使用recent_time()函數來查找最近的日期。 然后使用最近的日期查找該過程的完整文檔。

我的MongoDB中的文檔如下所示:

{"_id":"<key_id_here>",
"Process":"Process1",
"Shortnum":"002494",
"Status":1,
"Start_Time":"2019-06-12T07:53:22.000Z",
"Finish_Time":"2019-06-12T08:05:33.000Z"}

我的查詢應返回Shortnum但它不返回任何內容。 我也覺得很奇怪,如果我使用{Finish_Time: '2019-06-12T08:05:33.000Z'}在Compass應用程序中查詢它,它會返回正確的文檔。 任何幫助表示贊賞!

x = await dbo.collection("master").find({Process: "Process1"}).toArray();

如果這一行沒有返回任何內容,問題將通過de“Process”,你可以嘗試更改為this,或在console.log中顯示返回嗎?

x = await dbo.collection("master").find({"Process": "Process1"}).toArray();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM