Mongo Java Driver. The issue desn't appear to be the driver pushing/
pulling to/from MongoDB. Its the parsing of the BSON file.
db is a refenece to the Mongo database
br is a BufferedReader to the BSON file
[code]
while ((thisLine = br.readLine()) != null) {
Map<String, Object> objectInMap =
mapper.readValue(thisLine.getBytes(), new TypeReference<Map<String,
Object>>() {});
BasicDBObjectBuilder b = BasicDBObjectBuilder.start(objectInMap);
DBObject dbObject = b.get();
BasicDBObject dbObject = new BasicDBObject(objectInMap);
db.getCollection(collection).insert(dbObject);
}
[/code]
On Apr 26, 11:36 am, Scott Hernandez <
scotthernan...@gmail.com> wrote:
> How are you building that object? Are you parsing it from a string? If
> so, are you using the JSON class in the driver?
>
>
>
>
>
>
>
> On Thu, Apr 26, 2012 at 5:58 AM, PCimino <
pcim...@gmail.com> wrote:
> > Programatically created a an object with a reference. I can see and
> > export the data. In Java, I can load and reload the data from MongoDB.
>
> > Now I want to read it back in from a BSON file for unit tests.
>
> > The com.mongodb.DBCollection.validateKey() is throwing
> > java.lang.IllegalArgumentException: fields stored in the db can't
> > start with '$' (Bad Key: '$ref')
>
> > Objects look like this:
>
> > Parent:
> > {
> > "_id" : ObjectId("4f97f90b697eadc853dc0b4c"),
> > "_class" : "com.myorg.CustomerDetails",
> > "customerAddress" : {
> > "$ref" : "customerAddress",
> > "$id" : ObjectId("000000000000000000000011")
> > }
> > }
>
> > Reference Object:
> > {
> > "_id" : ObjectId("000000000000000000000011"),
> > "_class" : "com.myorg.CustomerAddress",
> > }
>
> > --
> > You received this message because you are subscribed to the Google Groups "mongodb-user" group.> To post to this group, send email
tomongo...@googlegroups.com.> To unsubscribe from this group, send email
tomongodb-use...@googlegroups.com.