MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Converti la stringa in ObjectID in MongoDB

Usando la mangusta:

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

Utilizzo del driver nativo (https://stackoverflow.com/a/21076589/3377073)

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