http://www.mongodb.org/display/DOCS/Java+Types
http://www.mongodb.org/display/DOCS/BSON
http://bsonspec.org/#/specification
So far testing seems to indicate this (with the 1.4 java driver):
java - mongodb
int -> int
long -> long
String -> String
boolean -> boolean
float -> double
double -> double
short -> double (huh?)
byte -> double (wha-what?)
http://www.idevelopment.info/data/Programming/java/miscellaneous_java/Java_Primitive_Types.html
The strange thing here is the short/byte java driver conversion. I
don't know about you, but I expected an int if short/byte wasn't
supported.
protected int putNumber( String name , Number n ){
int start = _buf.position();
if ( n instanceof Integer ){
_put( NUMBER_INT , name );
_buf.putInt( n.intValue() );
}
else if (n instanceof Long ) {
_put( NUMBER_LONG , name );
_buf.putLong( n.longValue() );
}
> --
> You received this message because you are subscribed to the Google Groups "mongodb-dev" group.
> To post to this group, send email to mongo...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-dev?hl=en.
>
It might be better to throw an exception rather than convert silently...
Definitely agree double is wrong though.
Whatever people seem to want I can do.
My bigger question is, what are the supported datatypes? It is hard to
suggest behavior without knowing what the options are :)
BSON Java
NULL null
UNDEFINED null
BOOLEAN Boolean
NUMBER Double
NUMBER_INT Integer
NUMBER_LONG Long
SYMBOL String
STRING String
OID mongodb ObjectID
REF DBPointer
DATE Date
REGEX Pattern
BINARY DBBinary
CODE (exception)
ARRAY DBList
OBJECT DBObject or DBRef
TIMESTAMP DBTimestamp
MINKEY String: "MinKey"
MAXKEY String: "MaxKey"
Java to BSON is similar (tests are done via instanceof, from top to bottom):
Java BSON
null NULL
Date DATE
Integer NUMBER_INT
Long NUMBER_LONG
Number NUMBER
String STRING
ObjectID OID
DBObject OBJECT
Boolean BOOLEAN
Pattern PATTERN
DBRegEx PATTERN (deprecated)
Map OBJECT
List ARRAY
byte[] BINARY
DBBinary BINARY
generic[] ARRAY
DBPointer REF (deprecated)
DBRefBase OBJECT
DBSymbol SYMBOL
DBUndefined UNDEFINED
DBTimestamp TIMESTAMP
Not sure about Character.
My inclination right now is to leave the current behavior (throwing exception).
I don't love the idea of converting to String or Integer
Having the system map byte -> double seemed very confusing; esp since
there seems to be a byte (8bit) datatype in BSON (or have I misread
the spec?).
I'd say char -> String is a better mapping, but less space efficient.
Eliot, sounds good with short<->int.
On Fri, Mar 26, 2010 at 11:06 AM, Eliot Horowitz
There is a bool type, but that wouldn't work.
Not sure why - but char -> String seems wrong to me... Not sure why
On Fri, Mar 26, 2010 at 2:10 PM, Scott Hernandez
<scotthe...@gmail.com> wrote:
Maybe you are correct, and we should leave char off the conversion list
On Fri, Mar 26, 2010 at 11:13 AM, Eliot Horowitz
I can't even think of a strawman example where I'd want to store a char in the database where I wouldn't want to just specify a string instead.
I'd vote for explicitly throwing an exception in this case.
Matt.
If we had to choose a mapping in the driver, I would go with String
because it is easier to read when looking at the output from on the
screen. I know what "M" looks like but it would take me a while to
lookup "M"'s ansi/unicode number (and that is depending on the
charset too).
On Mar 26, 11:23 am, Matt Mastracci <matt...@mastracci.com> wrote:
> char is always ambiguous in Java - you're never sure if it's being used as an unsigned short or a real character. I wouldn't be surprised if it threw an exception or was auto-converted to string, but I'd probably be surprised if it was auto-converted to an integer.
>
> I can't even think of a strawman example where I'd want to store a char in the database where I wouldn't want to just specify a string instead.
>
> I'd vote for explicitly throwing an exception in this case.
>
> Matt.
>
> On 2010-03-26, at 12:13 PM, Eliot Horowitz wrote:
>
>
>
> > There is a byte construct, but not a type.
>
> > There is a bool type, but that wouldn't work.
>
> > Not sure why - but char -> String seems wrong to me... Not sure why
>
> > On Fri, Mar 26, 2010 at 2:10 PM, Scott Hernandez
> > <scotthernan...@gmail.com> wrote:
> >> Cool, thanks for pulling that out, Matt.
>
> >> Having the system map byte -> double seemed very confusing; esp since
> >> there seems to be a byte (8bit) datatype in BSON (or have I misread
> >> the spec?).
>
> >> I'd say char -> String is a better mapping, but less space efficient.
>
> >> Eliot, sounds good with short<->int.
>
> >> On Fri, Mar 26, 2010 at 11:06 AM, Eliot Horowitz
> >> <eliothorow...@gmail.com> wrote:
> >>> Ok - changed Short and Byte to be INTEGERs
>
> >>> Not sure about Character.
> >>> My inclination right now is to leave the current behavior (throwing exception).
> >>> I don't love the idea of converting to String or Integer
>
> >>>>>>>>http://www.idevelopment.info/data/Programming/java/miscellaneous_java...
>
> >>>>>>>> The strange thing here is the short/byte java driver conversion. I
> >>>>>>>> don't know about you, but I expected an int if short/byte wasn't
> >>>>>>>> supported.
>
> >>>>>>>> --
> >>>>>>>> You received this message because you are subscribed to the Google Groups "mongodb-dev" group.>>>>>>>> To post to this group, send email tomong...@googlegroups.com.>>>>>>>> To unsubscribe from this group, send email tomongodb-de...@googlegroups.com.
> >>>>>>>> For more options, visit this group athttp://groups.google.com/group/mongodb-dev?hl=en.
>
> >>>>>>> --
> >>>>>>> You received this message because you are subscribed to the Google Groups "mongodb-dev" group.>>>>>>> To post to this group, send email tomong...@googlegroups.com.>>>>>>> To unsubscribe from this group, send email tomongodb-de...@googlegroups.com.
> >>>>>>> For more options, visit this group athttp://groups.google.com/group/mongodb-dev?hl=en.
>
> >>>>>> --
> >>>>>> You received this message because you are subscribed to the Google Groups "mongodb-dev" group.>>>>>> To post to this group, send email tomong...@googlegroups.com.>>>>>> To unsubscribe from this group, send email tomongodb-de...@googlegroups.com.
> >>>>>> For more options, visit this group athttp://groups.google.com/group/mongodb-dev?hl=en.
>
> >>>>> --
> >>>>> You received this message because you are subscribed to the Google Groups "mongodb-dev" group.>>>>> To post to this group, send email tomong...@googlegroups.com.>>>>> To unsubscribe from this group, send email tomongodb-de...@googlegroups.com.
> >>>>> For more options, visit this group athttp://groups.google.com/group/mongodb-dev?hl=en.
>
> >>>> --
> >>>> You received this message because you are subscribed to the Google Groups "mongodb-dev" group.>>>> To post to this group, send email tomong...@googlegroups.com.>>>> To unsubscribe from this group, send email tomongodb-de...@googlegroups.com.
> >>>> For more options, visit this group athttp://groups.google.com/group/mongodb-dev?hl=en.
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups "mongodb-dev" group.>>> To post to this group, send email tomong...@googlegroups.com.>>> To unsubscribe from this group, send email tomongodb-de...@googlegroups.com.
> >>> For more options, visit this group athttp://groups.google.com/group/mongodb-dev?hl=en.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups "mongodb-dev" group.>> To post to this group, send email tomong...@googlegroups.com.>> To unsubscribe from this group, send email tomongodb-de...@googlegroups.com.
> >> For more options, visit this group athttp://groups.google.com/group/mongodb-dev?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups "mongodb-dev" group.> To post to this group, send email tomong...@googlegroups.com.> To unsubscribe from this group, send email tomongodb-de...@googlegroups.com.