0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/insert1.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

t = db.insert1;
t.drop();
o = {a:1};
2010-03-01 16:33:52 +01:00
t.insert(o);
2010-03-02 05:16:36 +01:00
id = t._lastID
assert.eq(o, {a:1}, "input unchanged 1");
assert.eq(typeof(id), "object", "1");
assert.eq(id.constructor, ObjectId, "1");
assert.eq(t.findOne({_id:id}).a, 1, "find by id 1");
assert.eq(t.findOne({a:1})._id, id , "find by val 1");
o = {a:2, _id:new ObjectId()};
id1 = o._id
2010-03-01 16:33:52 +01:00
t.insert(o);
2010-03-02 05:16:36 +01:00
id2 = t._lastID
assert.eq(id1, id2, "ids match 2");
assert.eq(o, {a:2, _id:id1}, "input unchanged 2");
assert.eq(typeof(id2), "object", "2");
assert.eq(id2.constructor, ObjectId, "2");
assert.eq(t.findOne({_id:id1}).a, 2, "find by id 2");
assert.eq(t.findOne({a:2})._id, id1 , "find by val 2");
o = {a:3, _id:"asdf"};
id1 = o._id
2010-03-01 16:33:52 +01:00
t.insert(o);
2010-03-02 05:16:36 +01:00
id2 = t._lastID
assert.eq(id1, id2, "ids match 3");
assert.eq(o, {a:3, _id:id1}, "input unchanged 3");
assert.eq(typeof(id2), "string", "3");
assert.eq(t.findOne({_id:id1}).a, 3, "find by id 3");
assert.eq(t.findOne({a:3})._id, id1 , "find by val 3");
o = {a:4, _id:null};
id1 = o._id
2010-03-01 16:33:52 +01:00
t.insert(o);
2010-03-02 05:16:36 +01:00
id2 = t._lastID
assert.eq(id1, id2, "ids match 4");
assert.eq(o, {a:4, _id:id1}, "input unchanged 4");
assert.eq(t.findOne({_id:id1}).a, 4, "find by id 4");
assert.eq(t.findOne({a:4})._id, id1 , "find by val 4");
var stats = db.runCommand({ collstats: "insert1" });
assert(stats.paddingFactor == 1.0);