MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

Converter string para ObjectID no MongoDB


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

Usando driver nativo (https://stackoverflow.com/a/21076589/3377073)
var ObjectId = require('mongodb').ObjectId;
doc._id = new ObjectId(doc._id); // wrap in ObjectID