Skip to content

Instantly share code, notes, and snippets.

@ttrelle
Created December 18, 2012 13:00
Show Gist options
  • Save ttrelle/4327774 to your computer and use it in GitHub Desktop.
Save ttrelle/4327774 to your computer and use it in GitHub Desktop.
MongoDB: JSON vs. BSON
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} )
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment