0

when i see the this answer// convert this type of string date And I followed it this way.

20170721123840+0900

var a = new Date({$concat: [ "2017"," ",
                                 "11"," ",
                                 "11"," ",
                                 "11",":",
                                 "11",":",
                                 "11"," ",
                                 "+0900" ]  } )
a

This is what I expected.

var b = new Date("2017 07 21 12:38:40 +0900")
b

ISODate("2017-07-21T03:38:40Z")

But this was the result.

ISODate("0NaN-NaN-NaNTNaN:NaN:NaNZ")

Why is this form coming out? What do you do to solve it?

3
  • You cannot "cast" types in an aggregation pipeline, which is of course the only place $concat can actually be used ( since it is an aggregation pipeline operator ). In the context you are trying you simply use regular JavaScript expressions to "concatenate" the strings. If your actual intent to is convert existing document data from "string" to BSON Date, then instead you must "loop" the results and update, as is also pointed out on the answers to the same question you reference. Commented Jul 27, 2017 at 2:35
  • @NeilLunn Thank you for your kind reply. So, is it impossible to convert a string date to a date type in a query to search for a period? Commented Jul 27, 2017 at 2:48
  • What is your actual question? Why do you have a "string" that is in "parts" you need to concatenate? If you have something different to do than is actually described in the linked questions and answers then Edit your question to show what you really need to do. Your question makes no mention of "query to search for a period". But you are perhaps asking something already answered in Find objects between two dates MongoDB Commented Jul 27, 2017 at 2:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.