keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.62k stars 2.21k forks source link

user defined ObjectId with keystone.createItems gets overwritten with new _id #4956

Open Joel-Mckay opened 5 years ago

Joel-Mckay commented 5 years ago

Expected behavior _id can be user defined for data/index restore operations

Actual/Current behavior ignores old _id and generates new _id every time (I am new to the api, so there may be a reason for this I haven't read about yet)

Steps to reproduce the actual/current behavior

 var keystone = require('keystone');
 var Types = keystone.Field.Types;
 const errors = require("errors");
 // ...
 //json object based on default User Model entry
 var backupAcc = JSON.parse('{"_id":"5d3f62bca9108026a732c9fa","logins":0,"password":"newTest","email":"mail@example.com","__v":0,"isAdmin":false,"name":{"last":"Sad","first":"Panda"}}');
 //
 // backupAcc['_id']='ObjectId("'+ backupAcc['_id']+'")';
 backupAcc['_id']= keystone.mongoose.Types.ObjectId( backupAcc['_id']);
 //
 var payload ={};
     payload['User'] = Array();
     payload['User'][0] = backupAcc;
 //
 keystone.createItems(payload, { verbose: true}, function (err, stats) { 
     //wrong '_id' generated upon insert, delete, and insert again

Environment Keystone 4 Node.js v12.6.0