const indexCollection = function(db, callback) { db.collection('documents').createIndex( { "a": 1 }, null, function(err, results) { console.log(results); callback(); } ); }; code example
Example: mongo db const insertDocuments
const insertDocuments = function(db, callback) {
// Get the documents collection
const collection = db.collection('documents');
// Insert some documents
collection.insertMany([
{a : 1}, {a : 2}, {a : 3}
], function(err, result) {
assert.equal(err, null);
assert.equal(3, result.result.n);
assert.equal(3, result.ops.length);
console.log("Inserted 3 documents into the collection");
callback(result);
});
}