我可以通过ObjCMongoDB库使用Mongo Aggregation Framework吗?(Can I use the Mongo Aggregation Framework via the O

编程入门 行业动态 更新时间:2024-10-25 07:23:16
可以通过ObjCMongoDB库使用Mongo Aggregation Framework吗?(Can I use the Mongo Aggregation Framework via the ObjCMongoDB library?)

我使用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.

更多推荐

本文发布于:2023-08-03 13:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391346.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以通过   ObjCMongoDB   Mongo   library   Framework

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!