MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

Konvertieren Sie den String in MongoDB in ObjectID

Mungo verwenden:

var mongoose = require('mongoose');
var objectId = mongoose.Types.ObjectId('569ed8269353e9f4c51617aa');

Verwenden des nativen Treibers (https://stackoverflow.com/a/21076589/3377073)

var ObjectId = require('mongodb').ObjectId;
doc._id = new ObjectId(doc._id); // wrap in ObjectID