Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added support for binary data (NSData)

  • Loading branch information...
commit 6b580eff8f87cd16be751b5864659187ab0d5df5 1 parent aee8dd4
@timburks authored
Showing with 22 additions and 4 deletions.
  1. BIN  mongoleaf.png
  2. +10 −2 objc/NuMongoDB.m
  3. +12 −2 run.nu
View
BIN  mongoleaf.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
12 objc/NuMongoDB.m
@@ -137,7 +137,10 @@ void add_object_to_bson_buffer(bson_buffer *bb, id key, id object)
bson_append_finish_object(arr);
}
else if ([object isKindOfClass:[NSNull class]]) {
- // ignore nulls
+ // ignore nulls
+ }
+ else if ([object isKindOfClass:[NSData class]]) {
+ bson_append_binary(bb, name, 0, [object bytes], [object length]);
}
else {
NSLog(@"We have a problem. %@ cannot be serialized to bson", object);
@@ -250,6 +253,11 @@ void add_bson_to_object(bson_iterator it, id object)
bson_iterator_init(&it2, subobject.data);
add_bson_to_object(it2, value);
break;
+ case bson_bindata:
+ value = [NSData
+ dataWithBytes:bson_iterator_bin_data(&it)
+ length:bson_iterator_bin_len(&it)];
+ break;
default:
fprintf(stderr, "(type %d)\n", bson_iterator_type(&it));
break;
@@ -347,7 +355,7 @@ - (NuMongoDBCursor *) find:(id) query inCollection:(NSString *) collection
- (NuMongoDBCursor *) find:(id) query inCollection:(NSString *) collection returningFields:(id) fields numberToReturn:(int) nToReturn numberToSkip:(int) nToSkip
{
bson *b = bson_for_object(query);
- bson *f = bson_for_object(fields);
+ bson *f = bson_for_object(fields);
mongo_cursor *cursor = mongo_find(conn, [collection cStringUsingEncoding:NSUTF8StringEncoding], b, f, nToReturn, nToSkip, 0 );
return [[[NuMongoDBCursor alloc] initWithCursor:cursor] autorelease];
}
View
14 run.nu
@@ -5,7 +5,7 @@
(set mongo (NuMongoDB new))
(puts "connecting")
-(mongo connectWithOptions:(dict host:"67.23.47.34"))
+(mongo connectWithOptions:(dict host:"127.0.0.1"))
(puts "connected")
(mongo dropCollection:"sample" inDatabase:"test")
@@ -15,7 +15,8 @@
(set sample (dict one:1
two:2.0
three:"3"
- four:(array "zero" "one" "two" "three")))
+ four:(array "zero" "one" "two" "three")
+ leaf:(NSData dataWithContentsOfFile:"mongoleaf.png")))
(set bson ((NuBSON alloc) initWithDictionary:sample))
@@ -52,3 +53,12 @@
(puts "ok")
+(set first (mongo findOne:(dict one:1) inCollection:collection))
+
+(puts (first description))
+
+(set leaf (first leaf:))
+
+
+(puts (eq leaf (NSData dataWithContentsOfFile:"mongoleaf.png")))
+
Please sign in to comment.
Something went wrong with that request. Please try again.