如何将由Newtonsoft序列化的.net json字符串转换为mongodb文档

时间:2016-03-18 05:51:33

标签: mongodb json.net

db.logs.aggregate(
{ 
  $project : {
    timestamp:'$timestamp',
    messageObject: JSON.parse('$message')
  }
}
);

返回

  

2016-03-18T09:20:21.100 + 0330 E QUERY [thread1] SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符:

     

@(壳):5:20

样本记录:

{
  "_id" : ObjectId("56eb95e53b3d5535fc423bd4"),
  "timestamp" : ISODate("2016-03-18T05:45:08.953Z"),
  "level" : "INFO",
  "thread" : "5",
  "logger" : "AuditFilter",
  "message" : "{
      \"UserId\":\"379263f1-d638-4d94-bc91-303f3458e8fe\",
      \"ServiceName\":\"Education.Controllers.HomeController\",
      \"MethodName\":\"Index\",\"Parameters\":\"{}\",
      \"ExecutionTime\":\"2016-03-18T09:15:08.4057688+03:30\",
      \"ExecutionDuration\":380,
      \"ClientIpAddress\":\"::1\",
      \"ClientName\":null,
      \"BrowserInfo\":\"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0\",
      \"CustomData\":null,
      \"Exception\":null
  }" 
}

0 个答案:

没有答案