[JAVA-1652] Valid JS output? Created: 12/Feb/15 Updated: 11/Sep/19 Resolved: 12/Feb/15 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | 2.13.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Greg Pfeil | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
We use the Java driver to make requests against MongoDB instances, but also to output the JS that a user would have to execute to perform the same operation themselves (EG, in the mongo console). Using `toString` generally works – BasicDBObjects look like {"key": value}, etc. But `bson.types.Code` ends up outputting something like `{"scope": {"myFun": {"$code": "function () {…}"}}}`, when it should be `{"scope": {"myFun": function () {…}}}}`. So … are we abusing toString too much? Is there some other operation that we can use to get the appropriate output? Or do we have to write the JS-compatible version ourselves? Thanks. |
| Comments |
| Comment by Ross Lawley [ 12/Feb/15 ] |
|
Hi Greg, The Java driver uses extended json so that information isn't lost and that the Json we produce can be round tripped back to a Document and this is why you are seeing the $code and function as a string. For future, the best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there. Ross |