@@ -100,6 +100,61 @@ describe('mongo db', function() {
100
100
} ) ;
101
101
} ) ;
102
102
103
+ it ( '$map maps docs with output in extra' , function ( done ) {
104
+ var snapshots = [
105
+ { type : 'json0' , id : 'test1' , v : 1 , data : { x : 1 , y : 1 } } ,
106
+ { type : 'json0' , id : 'test2' , v : 1 , data : { x : 2 , y : 2 } } ,
107
+ { type : 'json0' , id : 'test3' , v : 1 , data : { x : 3 , y : 2 } }
108
+ ] ;
109
+ var query = {
110
+ y : 2 ,
111
+ $sort : { x : 1 } ,
112
+ $map : function ( doc ) {
113
+ return doc . x ;
114
+ }
115
+ } ;
116
+
117
+ var db = this . db ;
118
+ async . each ( snapshots , function ( snapshot , cb ) {
119
+ db . commit ( 'testcollection' , snapshot . id , { v : 0 , create : { } } , snapshot , null , cb ) ;
120
+ } , function ( err ) {
121
+ if ( err ) return done ( err ) ;
122
+ db . query ( 'testcollection' , query , null , null , function ( err , results , extra ) {
123
+ if ( err ) return done ( err ) ;
124
+
125
+ // Since $map can return non-docs, the output is delivered in extra.
126
+ expect ( results ) . eql ( [ ] ) ;
127
+ expect ( extra ) . to . deep . equal ( [ 2 , 3 ] ) ;
128
+ done ( ) ;
129
+ } ) ;
130
+ } ) ;
131
+ } ) ;
132
+
133
+ it ( '$explain delivers output in extra' , function ( done ) {
134
+ var snapshots = [
135
+ { type : 'json0' , id : 'test1' , v : 1 , data : { x : 1 , y : 1 } } ,
136
+ { type : 'json0' , id : 'test2' , v : 1 , data : { x : 2 , y : 2 } } ,
137
+ { type : 'json0' , id : 'test3' , v : 1 , data : { x : 3 , y : 2 } }
138
+ ] ;
139
+ var query = { $explain : true , y : 2 } ;
140
+
141
+ var db = this . db ;
142
+ async . each ( snapshots , function ( snapshot , cb ) {
143
+ db . commit ( 'testcollection' , snapshot . id , { v : 0 , create : { } } , snapshot , null , cb ) ;
144
+ } , function ( err ) {
145
+ if ( err ) return done ( err ) ;
146
+ db . query ( 'testcollection' , query , null , null , function ( err , results , extra ) {
147
+ if ( err ) return done ( err ) ;
148
+
149
+ expect ( results ) . eql ( [ ] ) ;
150
+ // Just check for the presence of an explain result. The specific structure
151
+ // could vary between Mongo versions.
152
+ expect ( extra ) . to . be . an ( 'object' ) ;
153
+ done ( ) ;
154
+ } ) ;
155
+ } ) ;
156
+ } ) ;
157
+
103
158
it ( '$sort, $skip and $limit should order, skip and limit' , function ( done ) {
104
159
var snapshots = [
105
160
{ type : 'json0' , v : 1 , data : { x : 1 } , id : 'test1' , m : null } ,
0 commit comments