Skip to content

Commit

Permalink
Add ability to specify arbitrary ObjectIDs in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaughto authored Jul 19, 2017
1 parent 6bdc592 commit 43ed156
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ Fixtures.prototype.load = function() {
return Promise.resolve(db.collection(collectionName)).then(collection => {
const batch = collection.initializeUnorderedBulkOp();
docs.forEach(doc => {
for(var prop in doc){
if(String(doc[prop]).indexOf('ObjectID:') === 0){
doc[prop] = new ObjectID(String(doc[prop]).replace('ObjectID:', ''));
}
}
if(doc._id){
doc._id = new ObjectID(doc._id);
}
}
return batch.insert(doc);
});
if (batch.length === 0) {
Expand Down

0 comments on commit 43ed156

Please sign in to comment.