exception: can't convert from BSON type EOO to Date

前端 未结 8 1269
情歌与酒
情歌与酒 2020-11-28 10:26

I am getting an issue for running the following aggregate query:

db.snippets.aggregate([ { \'$project\': { month: { \'$month\': \'$created_at\' }} } ])
         


        
8条回答
  •  北海茫月
    2020-11-28 11:06

    I had a related issue, but in my case the Date fields were the members of an array, so the error was "can't convert BSON type Object to Date".

    I needed to get the day of week from the dates in the possibleTripDateTimes array.

    Sample document:

    {
    "possibleTripDateTimes" : [
        {
            "tripDateTime" : ISODate("2015-08-01T06:00:00.000-0700")
        }
    ]
    }
    

    The fix was simply to use dot notation to address the array member fields.

    db.trips.aggregate([
      {
           $project: {
             departTime: {
               $map: {
                 input: "$possibleTripDateTimes.tripDateTime",
                 as: "dateTime",
                 in: { $dayOfWeek: "$$dateTime" }
               }
       }
      }
    }
    ]
    );
    

    I hope this helps someone who also gets zero search results on the "BSON type Object" search

提交回复
热议问题