我试图Mongo Query
在运行时构建,所以解析JSON string
为DBObject
.
我试过如下:
String then = "{$set : {"JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "Waltham", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "MA", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "Middlesex", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "USA", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "02451", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "42.398708", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "-71.259216", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "71650: Metropolitan NECTA |715: Combined NECTA", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "71654: NECTA Division", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "DV257165|MT257165", "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "781"}}"
DBObject thenQuery = (DBObject) JSON.parse(then);
结果 :
{ "$set" : { "JobDoc.DataElementsRollup.ConsolidatedONET.#text.$" : "781"}}
如果我出错了,任何人都可以对我进行排序,否则可以提出解决方法吗?