File: server6127.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (58 lines) | stat: -rw-r--r-- 1,497 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * SERVER-6127 : $project uasserts if an expected nested field has a non object parent in a document
 *
 * This test validates the SERVER-6127 ticket. Return undefined when retrieving a field along a
 * path, when the subpath does not exist (this is what happens when a field does not exist and
 * there is no path). Previous it would uassert causing the aggregation to end.
 */

/*
 * 1) Clear and create testing db
 * 2) Run an aggregation that simply projects a two fields, one with a sub path one without
 * 3) Assert that the result is what we expected
 */

// Clear db
db.s6127.drop();

// Populate db
db.s6127.save({a:1});
db.s6127.save({foo:2});
db.s6127.save({foo:{bar:3}});

// Aggregate checking the field foo and the path foo.bar
var s6127 = db.s6127.aggregate(
    { $project : {
        _id : 0,
        'foo.bar' : 1,
        field : "$foo",
        path : "$foo.bar"
    }}
);

/*
 * The first document should contain nothing as neither field exists, the second document should
 * contain only field as it has a value in foo, but foo does not have a field bar so it cannot walk
 * that path, the third document should have both the field and path as foo is an object which has
 * a field bar
 */
var s6127result = [
    {
    },
    {
        field : 2
    },
    {
        foo : {
                bar : 3
            },
        field : {
                bar : 3
            },
        path : 3
        
    }
];

// Assert
assert.eq(s6127.result, s6127result, 's6127 failed');