summaryrefslogtreecommitdiff
path: root/jstests/core/find_and_modify_empty_coll.js
blob: c47674c800ab4ea4d28c1d6b21682c0d91671bd2 (plain)
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
// Cannot implicitly shard accessed collections because of following errmsg: A single
// update/delete on a sharded collection must contain an exact match on _id or contain the shard
// key.
// @tags: [assumes_unsharded_collection]

/**
 * Test that findAndModify works against a non-existent collection.
 */
(function() {
'use strict';
var coll = db.find_and_modify_server18054;
coll.drop();

assert.eq(null, coll.findAndModify({remove: true}));
assert.eq(null, coll.findAndModify({update: {$inc: {i: 1}}}));
var upserted =
    coll.findAndModify({query: {_id: 0}, update: {$inc: {i: 1}}, upsert: true, new: true});
assert.eq(upserted, {_id: 0, i: 1});

coll.drop();

assert.eq(null, coll.findAndModify({remove: true, fields: {z: 1}}));
assert.eq(null, coll.findAndModify({update: {$inc: {i: 1}}, fields: {z: 1}}));
assert.eq(null, coll.findAndModify({update: {$inc: {i: 1}}, upsert: true, fields: {z: 1}}));
})();