我使用ObjCMongoDB库来支持一个简单的iPad应用程序。 我理解基本的CRUD操作以及使用-[MongoConnection runCommandWithDictionary:onDatabaseName:error:]来执行数据库命令,例如findAndModify 。
关于聚合框架或一般只是聚合,看起来我可以通过以下方式执行简单的数据库命令,如count :
NSDictionary *commandDict = @{@"count": @"myCollection"}: [myMongoConnection runCommandWithDictionary:commandDict onDatabaseName:@"myDB" error:&err];是否可以像这里的例子那样执行更复杂的命令/查询? 我尝试了以下无济于事。
NSDictionary *commandDict = @{@"aggregate":@"myCollection", @"query": @{@"group":@"myDocType"}};如果这是一个不知情的问题,我仍然在学习Obj-C和MongoDB。
I am using the ObjCMongoDB library to back a simple iPad application. I understand the basic CRUD operations as well as use of -[MongoConnection runCommandWithDictionary:onDatabaseName:error:] to execute database commands such as findAndModify.
With respect to the Aggregation Framework or just aggregation in general, it looks like I can execute simple database commands like count in the following manner:
NSDictionary *commandDict = @{@"count": @"myCollection"}: [myMongoConnection runCommandWithDictionary:commandDict onDatabaseName:@"myDB" error:&err];Is it possible to execute more complex commands/queries like the examples here? I tried the following to no avail.
NSDictionary *commandDict = @{@"aggregate":@"myCollection", @"query": @{@"group":@"myDocType"}};Am still learning both Obj-C as well as MongoDB so apologies if this is an uninformed question.
最满意答案
您的aggregate命令的语法似乎不正确。
从聚合的文档中查看此示例:
db.runCommand( { aggregate : "article", pipeline : [ { $project : { author : 1, tags : 1, } }, { $unwind : "$tags" }, { $group : { _id : "$tags", authors : { $addToSet : "$author" } } } ] } );如果从命令行运行Mongo shell,则可以在Objective-C中编写命令之前直接测试命令。
Your syntax for the aggregate command appears to be incorrect.
See this example from the docs for aggregate:
db.runCommand( { aggregate : "article", pipeline : [ { $project : { author : 1, tags : 1, } }, { $unwind : "$tags" }, { $group : { _id : "$tags", authors : { $addToSet : "$author" } } } ] } );If you run the Mongo shell from the command line, you can test your command directly right there, before writing it in Objective-C.
更多推荐
发布评论