Created
December 18, 2012 13:00
-
-
Save ttrelle/4327774 to your computer and use it in GitHub Desktop.
MongoDB: JSON vs. BSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use test | |
db.foo.drop(); | |
// in JSON all numbers are 32-bit floating point types (s. JSON spec) | |
// and thus are mapped to the 64-bit floating point type in BSON | |
db.foo.insert( {a: 1} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.UnknownHostException; | |
import com.mongodb.DBObject; | |
import com.mongodb.Mongo; | |
public class JsonVsBson { | |
public static void main(String argv[]) throws UnknownHostException { | |
DBObject doc = new Mongo().getDB("test").getCollection("foo").findOne(); | |
System.out.println( doc.get("a") ); | |
System.out.println( doc.get("a") instanceof Double); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.0 | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment