Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2faf81cc25
Fetching contributors…

Cannot retrieve contributors at this time

64 lines (49 sloc) 1.76 kb
// MECollection.m
// Mongo Explorer
// Created by François Beausoleil on 10-06-08.
// Copyright 2010 Solutions Technologiques Internationales. All rights reserved.
#import "MECollection.h"
#import "MEDatabase.h"
#import "MEConnection.h"
#import "MEDocument.h"
#import "MEUtils.h"
@implementation MECollection
@synthesize connection, database, fullName, name, documents;
-(id)initWithDatabase:(MEDatabase *)aDatabase info:(NSDictionary *)info connection:(MEConnection *)aConnection {
if (![super init]) return nil;
self.connection = aConnection;
self.database = aDatabase;
self.fullName = [info objectForKey:@"name"]; = [[info objectForKey:@"name"] stringByReplacingOccurrencesOfString:[ stringByAppendingString:@"."] withString:@""];
self.documents = [self reload];
return self;
-(void)dealloc {
self.connection = nil;
self.database = nil; = nil;
self.documents = nil;
[super dealloc];
-(NSArray *)reload {
if ([self.connection connect]) return [NSArray array];
NSMutableArray *results = [[NSMutableArray alloc] init];
bson query, fields;
const char* ns = [self.fullName cStringUsingEncoding:NSUTF8StringEncoding];
mongo_cursor *cursor = mongo_find([self.connection mongo_connection], ns, bson_empty(&query), bson_empty(&fields), 0, 0, 0);
while(mongo_cursor_next(cursor)) {
bson_iterator it;
bson_iterator_init(&it, cursor->;
NSDictionary *info = [MEUtils dictionaryFromBsonIterator:&it];
[results addObject:[[[MEDocument alloc] initWithCollection:self info:info connection:self.connection] autorelease]];
return results;
-(NSString *)description {
Jump to Line
Something went wrong with that request. Please try again.