I\'m using mongoose to operate mongodb. Now, for testing, I want to inserting some data into mongodb by native connection.
But the question is how to get the generat
If you like using Promises:
const collection = conn.collection('aaa');
const instance = new collection({ a: 'abc' });
instance.save()
.then(result => {
console.log(result.id); // this will be the new created ObjectId
})
.catch(...)
Or if you're using Node.js >= 7.6.0:
const collection = conn.collection('aaa');
const instance = new collection({ a: 'abc' });
try {
const result = await instance.save();
console.log(result.id); // this will be the new created ObjectId
} catch(...)